Skip to content

Jest Manual Mocks stop working react-scripts v2 #4344

Closed

Description

@TLadd

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): react-scripts@2.0.0-next.66cc7a90

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 react-scripts@2.0.0-next.66cc7a90, and now the test fails. The mocks is no longer taking effect.

Activity

  1. added this to the milestone on Apr 23, 2018
  2. bugzpodder commented on Jun 3, 2018

    @bugzpodder

    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.

  3. modified the milestones: 2.0.x, 2.x on Sep 26, 2018
  4. removed this from the 2.x milestone on Nov 2, 2018
  5. TLadd commented on Nov 22, 2018

    @TLadd
    Author

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

  6. locked and limited conversation to collaborators on Jan 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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