Bypassing module mocks
Consider writing a test case for this function:
Your test will want to mock the fetch
function so that we can be sure that it gets called without actually making the network request. However, you’ll also need to mock the return value of fetch
with a Response
(wrapped in a ), as our function uses it to grab the created user’s ID. So you might initially try writing a test like this:
To get around problems like this, Jest provides the jest.requireActual
helper. To make the above test work, make the following change to the imports in the test file: