Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest Manual Mocks stop working react-scripts v2 #4344

Closed
TLadd opened this issue Apr 23, 2018 · 2 comments
Closed

Jest Manual Mocks stop working react-scripts v2 #4344

TLadd opened this issue Apr 23, 2018 · 2 comments

Comments

@TLadd
Copy link

TLadd commented Apr 23, 2018

Is this a bug report?

Yes

Did you try recovering your dependencies?

Yes

Which terms did you search for in User Guide?

Manual Mocks

Environment

  1. node -v: v9.8.0
  2. npm -v: 5.6.0
  3. yarn --version (if you use Yarn): 1.5.1
  4. npm ls react-scripts (if you haven’t ejected): [email protected]

Then, specify:

  1. Operating system: macOS High Sierra
  2. Browser and version (if relevant): N/A

Steps to Reproduce

  1. Create a new project with create-react-app.
  2. Write a jest test that makes use of manual mocks. Ensure the test passes and that the mocked value is being used in the test.
  3. Upgrade react-scripts to 2.0.0-next.66cc7a90.
  4. Run the tests again and observe that the test no longer uses the mocked value

Expected Behavior

Jest manual mocks should still take effect

Actual Behavior

Jest manual mocks no longer work

Reproducible Demo

https://github.com/TLadd/manual-mocks-cra-test
The master branch is a newly-created CRA app and uses react-scripts 1.1.4. The only change is adding lodash.uniqueid as a dependency to the project, a src/uniqueId.js, src/tests/uniqueId.js, and mocks/lodash.uniqueid.js. The test just ensures that lodash.uniqueid returns the mocked value setup in mocks/lodash.uniqueid.js. The test passes on master.

On branch react-scripts-v2, the only change made is to update to [email protected], and now the test fails. The mocks is no longer taking effect.

@bugzpodder
Copy link

bugzpodder commented Jun 3, 2018

I tested this change, moving mocks from root to src/ works. Would that be okay? @TLadd
If you do yarn test --showConfig you'll see the root directory is configured to be src/ and according to the jest docs you referenced the mocks should be placed under the root dir.

@Timer Timer modified the milestones: 2.0.x, 2.x Sep 26, 2018
@Timer Timer removed this from the 2.x milestone Nov 2, 2018
@TLadd
Copy link
Author

TLadd commented Nov 22, 2018

__mocks__ in the root of the project works as expected again.

@TLadd TLadd closed this as completed Nov 22, 2018
@lock lock bot locked and limited conversation to collaborators Jan 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants