Jasmine and Requirejs in Resharper 7

前端 未结 3 794
情话喂你
情话喂你 2021-01-13 15:28

I\'m trying to run some JavaScript code using jasmine and Resharper 7 within visual studio 2012. I follow the AMD pattern with the aid of requirejs. However, i haven\'t mana

3条回答
  •  轮回少年
    2021-01-13 15:47

    Use a named requireJS Module

    define("my/sut", function () {
    
        var MySut = function () {
            return {
                answer: 42
            };
        };
        return MySut;
    });
    

    And initialize the SUT with the asyncronus support of Jasmine. Don't forgot the references!

    /// 
    /// 
    
    describe("requireJS with Jasmine and Resharper", function () {
    
        it("should be executed", function () {
    
            // init SUT async
            var sut;
            runs(function () {
                require(['my/sut'], function (MyModel) {
                    sut = new MyModel();
                });
            });
            waitsFor(function () {
                return sut;
            }, "The Value should be incremented", 100);
    
            // run the test
            runs(function () {
                expect(sut.answer).toBe(42);
            });
        });
    });
    

    I hope this works with more modules. In my case it worked with waitsFor '0' ms.

提交回复
热议问题