...
- Use expect.assertions(1) to ensure that the assertion inside your then() or catch() was called. This ensures that if your test is coded for then(), for example, it won't mistakenly pass if it is never called. Example code for expect.assertions(1).
- Return the promise in the test. If you do not, a failed assertion in your then() or catch() will not actually fail the test. Example code for returned promise.
- Here is example code for mocking a resolved promise (and a rejected promise example).
Unit Test Debugging
Note |
---|
Not sure how to do this from a container, but there should be a way. These instructions assume you are running node from your host. |
- add the line
debugger;
to your code where you want a breakpoint. From your project directory, run the following:
Code Block node --inspect-brk node_modules/.bin/jest --runInBand
- Open chrome browser, and navigate to chrome://inspect and click the device.
- You may need to click Play to get to your debugger line.