Skip to content

Jest.mock does not resolve modules correctly when NODE_PATH is set #1271

Closed
@dapids

Description

@dapids

Description

Running tests with NODE_PATH=src npm test.

Expected behavior

jest.mock('my_module') should be resolved to src/my_module.

Actual behavior

jest.mock('my_module') does not resolve to src/my_module.

Environment

  1. npm ls react-scripts (if you haven’t ejected): 0.8.4
  2. node -v: v6.9.2
  3. npm -v: 3.10.9

Activity

added this to the 0.9.1 milestone on Feb 11, 2017
EnoahNetzach

EnoahNetzach commented on Feb 12, 2017

@EnoahNetzach
Contributor

@mzuccala could you please update react-scripts to v0.9.0 and confirm that tests are still green?

modified the milestones: 0.9.2, 0.9.1, 0.9.4, 0.9.3 on Feb 24, 2017
gaearon

gaearon commented on Mar 5, 2017

@gaearon
Contributor

I verified that this indeed happens, but only if you import it relatively in jest.mock call but absolutely in the app code, or vice versa. This doesn’t seem to happen if you import files consistently in one way or another both in app and jest.mock() calls. So the workaround is to use a consistent convention across your whole app.

I agree this seems like a big, and I filed it as jestjs/jest#3069. It is highly unlikely that we can do anything about it on our side, so I’ll close this issue. Please feel free to track jestjs/jest#3069 (and maybe even contribute a fix!)

removed this from the 0.9.4 milestone on Mar 5, 2017
gaearon

gaearon commented on May 19, 2017

@gaearon
Contributor

This was fixed in react-scripts@1.0.1.

locked and limited conversation to collaborators on Jan 21, 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

        Participants

        @EnoahNetzach@gaearon@dapids

        Issue actions

          Jest.mock does not resolve modules correctly when NODE_PATH is set · Issue #1271 · facebook/create-react-app