My test case below passes but my Assertion failed. Why is it passing? I already have async in place and the updateSpy is not even called which is confirmed by my Assertion failed message. I also tried Done with promises.
it('should call the update method once', async () => {
const updateSpy = sinon.spy(() => 'Spy!');
sinon.stub(service, 'db').resolves({
collection(collectionName) {
return {
update: updateSpy,
};
},
});
console.assert(updateSpy.called); // assertion failed but the test case was passed
});
From the ASSERTIONS doc:
Mocha allows you to use any assertion library you wish. In the above example, we’re using Node.js’ built-in
assertmodule — but generally, if it throws anError, it will work!
But console.assert() method writes an error message to the console if the assertion is false. If the assertion is true, nothing happens. It will NOT throw an Error if the assertion is false.