Is there a way to get Chai working with asynchronous Mocha tests?

后端 未结 13 2198
自闭症患者
自闭症患者 2020-11-29 21:06

I\'m running some asynchronous tests in Mocha using the Browser Runner and I\'m trying to use Chai\'s expect style assertions:

window.expect = chai.expect;
d         


        
13条回答
  •  醉话见心
    2020-11-29 21:32

    What worked very well for me icm Mocha / Chai was the fakeTimer from Sinon's Library. Just advance the timer in the test where necessary.

    var sinon = require('sinon');
    clock = sinon.useFakeTimers();
    // Do whatever. 
    clock.tick( 30000 ); // Advances the JS clock 30 seconds.
    

    Has the added bonus of having the test complete quicker.

提交回复
热议问题