Promise object is already supported by all the major browsers including Chrome, Firefox, and Safari.
Despite making asynchronous code simpler, dealing with promises in unit tests is a hassle. You need to wire your test’s assertions into the callbacks of the promise, which adds extra code into the test. In this way the test itself becomes a bit complicated and it’s harder to see what’s happening.
In this article, I’ll show you how to fix this issue and discuss about useful patterns which are able to simplify common promise-scenarios in tests’ stage.
I’ve created an example project that you can download from my website which shows the techniques introduced in this article.
For this project I’ll use Mocha as the testing framework and the Chai library to provide the assertions. You’ll understand why in a moment.
LEAVE A REPLY
You must be logged in to post a comment.