Testing Asynchronous Callbacks with Jasmine

前端 未结 1 1411
-上瘾入骨i
-上瘾入骨i 2020-12-07 02:33

I\'m using Jasmine 2.1. I am trying to use Jasmine 2.1 to test a module. One of my modules has a function that executes code asynchronously. I need to test the result of the

相关标签:
1条回答
  • 2020-12-07 03:08

    I would recommend taking a look at the async section of the jasmine docs. So, with this information we can use a done callback to wait for the execution to finish before testing anything, like this:

    var MyModule= require('./myModule');
    describe("My Module", function() {
      var myModule = new MyModule();
      it('Execute', function(done) {
        myModule.execute(function(){
            expect(myModule.state).toBe('Executed');
            done();
        });
      });
    });
    
    0 讨论(0)
提交回复
热议问题