Tests after upgrading [react-scripts] to version 4 fail
See original GitHub issueDescribe the bug
After updating react-scripts to version 4+ more than half of the tests started to fail. But if I run any of the failing tests in VSCode or from jest they don’t fail and work as before.
Looks like any of the mocks I use in my ./src/setupTests.ts
file aren’t picked up when I run react-scripts test
.
Did you try recovering your dependencies?
Yes. I did.
Which terms did you search for in User Guide?
They are not related to the issue.
Environment
System: OS: macOS 11.1 CPU: (8) x64 Intel® Core™ i7-4750HQ CPU @ 2.00GHz Binaries: Node: 15.8.0 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/Cellar/node/15.8.0/bin/yarn npm: 7.5.0 - /usr/local/Cellar/node/15.8.0/libexec/bin/npm Browsers: Chrome: 88.0.4324.182 Firefox: Not Found Safari: 14.0.2 npmPackages: react: ^17.0.1 => 17.0.1 react-dom: ^17.0.1 => 17.0.1 react-scripts: ^4.0.2 => 4.0.2 npmGlobalPackages: create-react-app: 4.0.2
Steps to reproduce
Expected behavior
Tests shouldn’t fail and work the same way as they work using Jest
Actual behavior
Failing test which uses mocked localStorage:
Failing test which uses mocked version of window.open:
Failing test which uses redux (I don’t mock redux, use the same createStore function which already has thunk middleware):
setupTests.ts
import 'jest-localstorage-mock';
import '@testing-library/jest-dom';
import 'jest-date-mock';
import './test-helpers/react-i18next.mock';
window.scrollTo = jest.fn();
window.open = jest.fn();
Issue Analytics
- State:
- Created 3 years ago
- Comments:9
Top GitHub Comments
Found an issue. From 4+ version of
react-scripts
--resetMocks
istrue
by default. Fixed it by makingreact-scripts test --resetMocks=false
.--resetMocks=false
flag and override withreact-app-rewired
worked for me