...
Testing that a Promise is resolved
Code Block | ||
---|---|---|
| ||
// Remember to use the 'async', 'await', and 'expect' below. it('tests that someMethodThatReturnsAPromise rejects with an error', async () => { // first, set up data such that the promise should be resolved // second, call the method await expect(someMethodThatReturnsAPromise()).resolves.toBe(undefined); }); |
Testing that a Promise is rejected
Code Block | ||
---|---|---|
| ||
// Remember to use the 'async', 'await', and 'expect' below. it('tests that someMethodThatReturnsAPromise rejects with an error', async () => { // first, set up data such that the promise should be rejected // second, call the method await expect(someMethodThatReturnsAPromise()).rejects .toThrow(new Error('The error sent to the reject.')); }); |
Mock that a Promise was resolved
Code Block | ||
---|---|---|
| ||
jest.spyOn(object, 'methodWithPromise').mockResolvedValue(undefined); |
Mock that a Promise was rejected
Code Block | ||
---|---|---|
| ||
jest.spyOn(object, 'methodWithPromise').mockRejectedValue(new Error('test')); |
Mocking Top-level Objects (e.g. document)
Code Block | ||
---|---|---|
| ||
jest.spyOn(global.document, 'referrer', 'get').mockReturnValue(loginUrl); |
...
- add the line
debugger;
to your code where you want a breakpoint. From your project directory, run the following:
Code Block language bash 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.
...