I use chai-as-promised to test some promises. My problem: I'm not sure how to have multiple pending statements in one test. For proper operation, expect().to.be.fulfilledI need to return it, for example:
it('test', () => {
return expect(promise).to.be.fulfilled
}
... or use notifyfor example:
it('test', (done) => {
expect(promise).to.be.fulfilled.notify(done)
}
The problem occurs when I have one more thing that I need to check, for example, that a certain function is called, for example:
it('test', (done) => {
var promise = doSomething()
expect(sinon_function_spy.callCount).to.equal(1)
expect(promise).to.be.fulfilled.notify(done)
})
The problem is that since it doSomething()is asynchronous, the call sinon_function_spymay not happen when I call it expect, making this test flaky. If I use then, for example:
it('test', (done) => {
var promise = doSomething()
promise.then(() => {
expect(sinon_function_spy.callCount).to.equal(1)
})
expect(promise).to.be.fulfilled.notify(done)
})
, , , - then. , , , :
it('test', (done) => {
var promise = doSomething()
promise.then(() => {
expect(sinon_function_spy.callCount).to.equal(1)
})
expect(promise).to.be.rejected.notify(done)
})
sinon_function_spy , then.
expect ?