Reputation: 4847
When I add the following code to my package.json
I get an error saying it is not supported:
"jest": {
"resetMocks": true
},
Thanks in advance!
Upvotes: 3
Views: 3346
Reputation: 45810
Solution
Add the following to src/setupTests.js
:
beforeEach(() => {
jest.resetAllMocks()
})
Details
The documentation for the resetMocks
option states that setting it to true
is "Equivalent to calling jest.resetAllMocks() between each test."
Looking at the Jest
source shows that the check for config.resetMocks
happens within a beforeEach()
and if true
it calls jest.resetAllMocks()
.
Apps bootstrapped with create-react-app
that are using react-scripts
version 0.4.0
or higher will automatically run src/setupTests.js
to initialize the test environment before each test runs.
So adding the above code to src/SetupTests.js
is equivalent to setting the resetMocks
option to true
for a non-create-react-app
app.
Upvotes: 7