Closed MarcusNoble closed 6 years ago
Hey! Sorry you're having trouble.
It's true that it resolves to a promise that fails. What you need to do to have your test fail, too, is to pass that failing promise to Mocha for it to listen to it and not presume your test succeeded.
Doing something like the following should do it:
it("must pass", function() {
return demand(Promise.resolve(false)).to.resolve.to.equal(true)
})
I myself usually find it easier to use CoMocha and use generators to not have to do so. Check out one of my open source websites for an full blown example: https://github.com/rahvaalgatus/rahvaalgatus. Particularly https://github.com/rahvaalgatus/rahvaalgatus/blob/master/test/mocha.opts and the controller tests at https://github.com/rahvaalgatus/rahvaalgatus/blob/master/test/controllers/home_controller_test.js.
Ah! Returning the assert works, as does await
ing that line.
Perhaps it's worth adding a little note to the readme?
You're probably right wrt to README/docs. ;)
I'm not sure if i've come across a bug or if my understanding of the API is incorrect but I am having trouble testing for a promise either resolving or rejecting.
I am testing similar to this:
When calling a function that returns a promise that resolves without a value. This passes as I'd expect it to.
The problem occurs when I switch out the function with one that rejects:
This still passes, even though the promise rejected.
An example can be found here: https://glitch.com/edit/#!/icy-creator
The output of running these tests are: