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

Tests fail in a react-native-web app with __DEV__ is not defined #1085

Closed
tlvince opened this issue Nov 22, 2016 · 2 comments · Fixed by #1201
Closed

Tests fail in a react-native-web app with __DEV__ is not defined #1085

tlvince opened this issue Nov 22, 2016 · 2 comments · Fixed by #1201

Comments

@tlvince
Copy link

tlvince commented Nov 22, 2016

In a fresh app created by create-react-app using React Native for Web, running src/root/Root.test.js throws ReferenceError: __DEV__ is not defined.

I would assume an equivalent of #407 (aliasing react-native to react-native-web) is necessary in the test environment. If I temporarily manually symlink react-native-web to react-native in node_modules and re-run the tests, they pass as expected.

Expected behavior

Tests to pass.

Actual behaviour

 FAIL  src/root/Root.test.js
  ● Test suite failed to run

    ReferenceError: __DEV__ is not defined
      
      at Object.<anonymous> (node_modules/react-native/Libraries/react-native/react-native.js:15:5)
      at Object.<anonymous> (src/app/App.js:3:18)
      at Object.<anonymous> (src/root/Root.js:3:10)
      at Object.<anonymous> (src/root/Root.test.js:5:11)
      at process._tickCallback (internal/process/next_tick.js:103:7)

Environment

Run these commands in the project folder and fill in their results:

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

Then, specify:

  1. Operating system: OS X 10.10.5
  2. Browser and version: Chrome v53
@gaearon
Copy link
Contributor

gaearon commented Dec 5, 2016

This is probably fixable using moduleNameMapper as described here.
Something like

    "moduleNameMapper": {
      "^react-native$": "react-native-web",
    }

If this works, would you like to send a PR?

@remon-nashid
Copy link
Contributor

I've just stumbled that issue with similar circumstances; running tests in a CRA app while RNW is in use. @gaearon's suggestion works perfectly. Here is a pull request that includes the change #1201.

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

Successfully merging a pull request may close this issue.

3 participants