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

后端 未结 13 2172
自闭症患者
自闭症患者 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:12

    Based on this link provided by @richardforrester http://staxmanade.com/2015/11/testing-asyncronous-code-with-mochajs-and-es7-async-await/, describe can use a returned Promise if you omit the done parameter.

    Only downside there has to be a Promise there, not any async function (you can wrap it with a Promise, thou). But in this case, code can be extremely reduced.

    It takes into account failings from either in the initial funcThatReturnsAPromise function or the expectations:

    it('should test Promises', function () { // <= done removed
        return testee.funcThatReturnsAPromise({'name': 'value'}) // <= return added
            .then(response => expect(response).to.have.property('ok', 1));
    });
    

提交回复
热议问题