node_modules Mocks are not picked up by jest with latest react-scripts
See original GitHub issueDescribe the bug
When upgrading from react-scripts@3.0.1 to latest the mocks are no longer picked up from /__mocks__ directory
Did you try recovering your dependencies?
YES
Which terms did you search for in User Guide?
jest manual mocks broken
Environment
Environment Info:
System: OS: macOS 10.14.5 CPU: (8) x64 Intel® Core™ i7-7920HQ CPU @ 3.10GHz Binaries: Node: 12.8.0 - /usr/local/bin/node Yarn: 1.17.3 - ~/.yarn/bin/yarn npm: 6.10.2 - /usr/local/bin/npm Browsers: Chrome: 76.0.3809.100 Firefox: 68.0.1 Safari: 12.1.1 npmPackages: react: ^16.9.0 => 16.9.0 react-dom: ^16.9.0 => 16.9.0 react-scripts: 3.1.1 => 3.1.1 npmGlobalPackages: create-react-app: 2.1.3
Steps to reproduce
(Write your steps here:)
- create a manual mock of any node_modules package
- put it to mocks directory
- run your test
Expected behavior
Mocks are picked up by jest
Actual behavior
Mocks are not picked up
Reproducible demo
(Paste the link to an example project and exact instructions to reproduce the issue.)
- git clone https://github.com/tomitrescak/react-boilerplate -b Demo
- cd react-boilerplate
- yarn
- yarn test
- p -> ‘button’
- error: Trans not found (not being picked up by mocks)
To see that is works with previous react-scripts do
- yarn add react-scripts@3.0.1
- yarn test
- You will recieve a snapshot erro which is fine
Issue Analytics
- State:
- Created 4 years ago
- Reactions:36
- Comments:27 (5 by maintainers)
Top GitHub Comments
For those whose test’s are completely broken by this: Moving
__mocks__
under./src
solved the problem for me.@brendanmc6 the issue is this is an anti-pattern.
The Jest documentation says that any external module manual mocks must live in the same level as
node_modules
, see https://jestjs.io/docs/en/manual-mocks#mocking-node-modules