Skip to content

Tests after upgrading [react-scripts] to version 4 fail #10571

Closed
@wamujlb

Description

@wamujlb

Describe 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(R) Core(TM) 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:
Screenshot 2021-02-17 at 17 15 10

Failing test which uses mocked version of window.open:
Screenshot 2021-02-17 at 17 16 17

Failing test which uses redux (I don't mock redux, use the same createStore function which already has thunk middleware):
Screenshot 2021-02-17 at 17 17 55

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();

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions