Closed alexandradeas closed 6 years ago
The only one that's complex is expecting rejection - for expecting resolution, just return the promise directly. mocha will do the assertion for you (your expectReject works fine).
Promises don't expose their state, so there's be no way to have a synchronous assertion for them - which is why the test framework itself is the only thing that can assert on it.
Currently, I'm testing promises by following the pattern
Which eventually evolved into:
This can become difficult to orchestrate when the promise does more than a simple task. Is there a better way to test promises?
It'd be nice to write these as regular assertions though, such as: