js-testing-introduction
js-testing-introduction copied to clipboard
async code refactor
Added expect.assertions(1)
and return promise
from test case.
Below notes taken from "Jest docs"
expect.assertions(number) verifies that a certain number of assertions are called during a test. This is often useful when testing asynchronous code, in order to make sure that assertions in a callback actually got called.```
If your code uses promises, there is a simpler way to handle asynchronous tests. Just return a promise from your test, and Jest will wait for that promise to resolve. If the promise is rejected, the test will automatically fail.```