Consider the following mocha+chai+sinon test:
it("will invoke the 'then' callback if the executor calls its first argument", function(done){
let executor = function(resolve, reject){
resolve();
}
let p = new Promise(executor);
let spy = sinon.spy();
p.then(spy);
spy.should.have.been.called.notify(done);
});
As described in the assertion, I expected that the spy should have been called. However, mocha reports:
1) A Promise
will invoke the 'then' callback if the executor calls its first argument:
AssertionError: expected spy to have been called at least once, but it was never called
Substitution of the spy with a console.log demonstrates the expected flow, so I am confused as to why mocha reports the negative.
How do I change the test to prove the expected behaviour?