Jasmine and Requirejs in Resharper 7

前端 未结 3 766
情话喂你
情话喂你 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:49

    If you use Jasmine 2.0 or newer, you can support asynchronous calls in your code. Just pass the done parameter into the function for your it unit test, then call done() when you have loaded your modules:

    describe("add function", function(){
       it("calls renderNew", function(done){
          define("taskRenderer", [], function() {
             return {
                renderNew: function(){}
             };
          });
    
          require(["taskRenderer"], function(taskRenderer) {
             spyOn(taskRenderer, "renderNew");
             taskRenderer.renderNew();
             expect(taskRenderer.renderNew).toHaveBeenCalled();
             done();
          });
       }
    }
    

    This way, you don't actually perform your test until the modules are loaded and the test doesn't prematurely get marked as finished.

提交回复
热议问题