-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Cannot find module 'ReactNativeDefaultInjection' from 'setup.js' #1840
Comments
I add
FormCamera.js import React, { Component, PropTypes } from 'react';
import ProgressCircle from 'react-native-progress/Circle';
import ImagePreview from 'react-native-image-preview';
import ImageResizer from 'react-native-image-resizer';
... .babelrc {
"presets": [ "react-native", "react-native-stage-0/decorator-support"],
"plugins": [
"transform-object-rest-spread",
["module-resolver", {
"root": ["./"],
"alias": {
"src": "./src",
"config": "./config"
}
}]
]
} |
Which version of react-native are you using? |
@cpojer 0.34.0 |
Oh, remove the |
I'm having the exact same issue. Here's my package.json:
Any idea why it's not working? |
you don't seem to have react-native as a dependency of your project. |
I have it, but not as dev dependency, just as regular dependency, samo as @shixukai. |
I did some more research and if I put my test in __ tests __ folder, everything works fine. However, when I move them to /test/jest, and add this param:
Then it starts failing with ReactNativeDefaultInjection error. |
This issue definitely seems to be caused by setting the For example, change |
Currently testPathDirs is broken, so use this instead. jestjs/jest#1840
That's actually correct, |
Yes, |
I am running into this issue also on this repo, however I have not defined This project doesn't have an I've written basic tests based on the example here and have named them with the
Is there anything else which might cause this? |
@jasonmerino try |
When I ● The settings `scriptPreprocessor` and `preprocessorIgnorePatterns` were replaced by `transform` and `transformIgnorePatterns` which support multiple preprocessors.
Jest now treats your current settings as:
"transform": {".*": "undefined"}
"transformIgnorePatterns": "node_modules/(?!(jest-)?react-native|react-clone-referenced-element)"
Please update your configuration.
Jest changed the default configuration for tests.
Configuration Documentation: https://facebook.github.io/jest/docs/configuration.html
Jest Issue Tracker: https://github.com/facebook/jest/issues Which is strange since the only configuration I have in the package.json is the |
You also need |
Okay, I did Here's the output from my npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
[email protected] /Users/jason.merino/Code/react-native-splat
├── UNMET PEER DEPENDENCY [email protected]
├── [email protected] extraneous
└── [email protected] extraneous
npm WARN [email protected] requires a peer of eslint-plugin-import@^1.16.0 but none was installed.
npm WARN [email protected] requires a peer of eslint-plugin-import@^1.16.0 but none was installed. So it looks like I'm getting the test versions of |
+1 I have the same issue. |
Oh man, i figured this out. |
We had this issue to using We had this in our {
"react": "^15.3.2",
"react-native": "^0.37.0",
} and doing a
This was due Setting the react version to {
"react": "~15.3.2",
"react-native": "^0.37.0",
} |
even |
This problem occured to me once i upgraded to node from 6 to
|
This is happening to me with
but only on my CircleCI VM... locally everything runs fine. |
this issue happened to me after upgrading react-native to 0.38 and react to 15.4.1 it was fine using react-native @carera installing |
Can someone confirm? @Richard-Cao you've mention that on your local PC all is fine, and it breaks on CI server. May be it because You have case-INsensitive FS on local PC, and Linux FX is case-sensitive? |
Sorry for triple comment. let me explain a bit Where it's located: I've installed some last versions one-by-one, and this directive was suddendly disappear from transpiled code, throwing error from Haste, which can't resolve Versions and directive existence:
What was happen with transpiled source at So. For now, I have react-native
And What to do?
|
We haven't forwarded jest-react-native to react-native yet, unfortunately. cc @kentaromiura |
I'll update jest-react-native today to forward to react-native. I'm also updating Jest's documentation to hint that you won't need jest-react-native any longer as the default setup with 0.38 includes a working Jest configuration. I'm sorry that this was a problem for people. I was on vacation and we were unable to update See #2182. |
Hey @cpojer, I'm also stumbling into an issue since updating, but it's throwing this issue:
is this the same issue? Furthermore, I'm under the impression that updating to latest React and React-native is causing other issues as you can see at the bottom of this thread (facebook/react-native#4968), so I think I'll have to stick with older versions until issues with react + react-native are resolved as well? Kind regards, |
@JeroenNelen actually, issue You've linked ( facebook/react-native#4968 ), comes from npm - it has a bug with installing dependencies. Please refer to npm/npm#12654 . How to deal with this bug : personally, I don't use React-native is rapidly changing, probably sticking with old releases is not very good... But who knows, may be old RN version will work for someone! |
@JeroenNelen If you are using react-native prior to 0.38, use |
Hey, @cpojer, after updating I'm getting an error that seems to be related to mocking of native modules. Do I need to manually mock it? In one of my files I have:
When I run the tests it gives this error, which seems to be because
|
Yeah, we moved to more explicit mocks and StatusBar might simply not be mocked properly. See https://github.com/facebook/react-native/blob/master/jest/setup.js#L69 – you can send a PR to RN to fix this and meanwhile you can probably add this mock manually a file that you add to |
@cpojer What you suggested works great! We are on react-native 0.38 & setting the jest preset to |
When I typed 'npm run jest' I got this error. 'Invariant Violation: Native module cannot be null.' After updating react-native version(0.38), I got this error. |
@MechanicKim you'll need to post a stack trace for us to know which module is causing the problem, but a change similar to this one will probably be needed to properly mock the native module. |
@cooperka Thank you for your comment. In package.json Test file import Example from '../Example'; import renderer from 'react-test-renderer'; describe('Example', () => { I found the reason. The reason is because of Example.js import XXX from './components/XXX'; When I removed these lines, I could pass jest. |
So I am on the latest versions of React and React-native and the following versions of jest: However, I'm bumping into the Invariant Violation as well, mostly due to the react-native-experimental-navigation it seems (I'm using react-native-router-flux):
When trying to mock: It still throws the error. Anyone any suggestion or idea? Kind regards, |
I think this page is useful for you.
https://github.com/facebook/jest/issues
#2208
I have not tested yet.
I succeed when I used 'react-native 0.37' and 'jest 17.0.3'
"react": "15.3.1",
"react-native": "0.37.0",
"babel-jest": "^17.0.2",
"babel-preset-react-native": "^1.9.0",
"jest": "17.0.3",
"jest-react-native": "17.0.3",
"react-test-renderer": "15.3.0",
and jest preset is 'jest-react-native'
But, If you use react-native >= 0.38, you should fix 'jest-react-native'
--> 'react-native'
2016-12-05 18:52 GMT+09:00 JeroenNelen <[email protected]>:
… So I am on the latest versions of React and React-native and the following
versions of jest:
However, I'm bumping into the Invariant Violation as well, mostly due to
the react-native-experimental-navigation it seems (I'm using
react-native-router-flux):
Invariant Violation: Native module cannot be null.
at invariant (node_modules/fbjs/lib/invariant.js:38:15)
at Linking.NativeEventEmitter (node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:32:1)
at new Linking (node_modules/react-native/Libraries/Linking/Linking.js:119:141)
at Object.<anonymous> (node_modules/react-native/Libraries/Linking/Linking.js:191:16)
at Object.Linking (node_modules/react-native/Libraries/react-native/react-native.js:91:22)
at Object.<anonymous> (node_modules/react-native-experimental-navigation/NavigationRootContainer.js:15:36)
When trying to mock:
jest.mock('react-native-experimental-navigation', () => 'Mocked');
It still throws the error.
@MechanicKim <https://github.com/MechanicKim> , I also have imports like
that, to import the container or component that I want to test, so I don't
see how I can remove those imports and still test the code?
Anyone any suggestion or idea?
Kind regards,
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1840 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ALlkF7fKftElpPNyLMgQLpJR6PuCTKThks5rE97RgaJpZM4KL8lY>
.
|
@JeroenNelen this comment should fix your issue: #2208 (comment). If you're feeling generous, you can contribute by making a PR similar to this one that fixes the issue for everyone else, too. |
@cooperka @MechanicKim that indeed solves the navigation issue in the tests! Thanks! |
@mlanter @cpojer I created a PRQ to react-native to improve upon the statusBarManager mock, as I have some code that uses functions of the statusBarManager for which the tests are failing because they are not found (I was using setHidden, setStyle and SetNetwork...): |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
here is my config of jest
any idea?
The text was updated successfully, but these errors were encountered: