-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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 fails with "SyntaxError: Unexpected reserved word" everytime #256
Comments
cc: @ferrannp |
You need to use
So you can add in your
Unfortunately, it seems that we will still have an error related to PlatformHelpers.native.js:
So this is basically something we will need to look at. |
CC: @satya164 in terms of the latter. If that fixes the issue, maybe we should document it? I am afraid people get into troubles when trying to run basic test cases. |
After |
@grabbou @ferrannp thanks guys, I guess I missed that line in the doc. I'll be glad to help improve the documentation, and not only on that particular issue. |
Sounds really good, thank you! I am happy that we were able to help! I am flagging that one with |
@ferrannp Is there any way to force Jest to import ● Test suite failed to run
Invariant Violation: Native module cannot be null.
at invariant (node_modules/fbjs/lib/invariant.js:44: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.get Linking [as Linking] (node_modules/react-native/Libraries/react-native/react-native.js:91:22)
at Object.<anonymous> (node_modules/react-navigation/src/PlatformHelpers.native.js:10:21) This happens after making the changes to my Jest configuration that @half-shell recommended. |
@matthamil I think that for now, in your app you can mock that |
@ferrannp Sorry, I don't think I understand exactly what you mean by mocking and implementing a manual mock? |
Thanks @ferrannp ! But, after changing my package.json, a new error has showing up :
In fact, it misses react-clone-referenced-element that we can find in jest-preset.json. So we need to add this in the package.json : Now it works for me :) |
Hi guys, I managed all this test-concerns (with jest) using this in my package.json {
.
.
.
"jest": {
"preset": "react-native",
"setupFiles": ["<rootDir>/jest/setup.js"],
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-navigation)"
]
},
.
.
.
} and this mock in /jest/setup.js jest.mock('Linking', () => ({
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
openURL: jest.fn(),
canOpenURL: jest.fn(),
getInitialURL: jest.fn(),
})); an this in my .flowconfig (in case you're using flow too)
I'm using Based on |
I've fixed the jest.mock('Linking', () => ({
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
openURL: jest.genMockFn().mockReturnValue(Promise.resolve()),
canOpenURL: jest.genMockFn().mockReturnValue(Promise.resolve()),
getInitialURL: jest.genMockFn().mockReturnValue(Promise.resolve()),
})) |
I think these should go into the |
Thanks @ferrannp! I was sure that should go to the RN repo, but I couldn't find exactly where. Will send a PR. |
For anyone visiting this in the future you can place @alvaromb's snippet into a file "jest": {
"preset": "react-native",
"verbose": true,
"setupFiles": [
"./jest/setup.js"
],
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-navigation)"
],
"moduleNameMapper": {
"^image![a-zA-Z0-9$_-]+$": "GlobalImageStub",
"^[@./a-zA-Z0-9$_-]+\\.(png|gif)$": "RelativeImageStub"
}
} That fixes the error Although I currently have unrelated issues now:
Edit: Cross-referencing the issue which reports the above stack trace and has a pull request up for it facebook/react-native#13034 👍 |
* master: add jest config for react-navigation in docs (react-navigation#256) (react-navigation#331)
Closed in e8726c1 |
Hi, Unfortunately, I still get this issue:
With: package.json "dependencies": { "react": "16.0.0-alpha.6", "react-native": "^0.44.0", "react-navigation": "1.0.0-beta.11" }, "devDependencies": { "babel-jest": "^20.0.3", "babel-preset-react-native": "^1.9.2", "jest": "^20.0.4", "react-test-renderer": "^16.0.0-alpha.6" }, "jest": { "preset": "react-native", "verbose": true, "setupFiles": [ "./jest-setup.js" ], "transformIgnorePatterns": [ "node_modules/(?!(jest-)?react-native|react-navigation)" ] }, .flowconfig [ignore] ; react-navigation isn't compatible with the newest flow version, ignore it .\*/node_modules/react-navigation\* jest-setup.js jest.mock('Linking', () => ({ addEventListener: jest.fn(), removeEventListener: jest.fn(), openURL: jest.genMockFn().mockReturnValue(Promise.resolve()), canOpenURL: jest.genMockFn().mockReturnValue(Promise.resolve()), getInitialURL: jest.genMockFn().mockReturnValue(Promise.resolve()), })) Is there something I'm missing ? |
I have the same failure as @Maxime-Antoine , I changed the jest import in Snapshots are not possible... my error message:
|
@grabbou you have any idea, why it is not working? |
@Maxime-Antoine Could you solve it? |
@KevKo1990 no, not yet |
@grabbou do you need anything else for investigating? |
@KevKo1990 @Maxime-Antoine If you didn't get this fixed. I faced the same issue and I had a stupid user error in my test configuration.
This configuration made the test fail with Exception:
Reason was that I was trying to test the AppRegistry file instead of the actual component so with the correct test:
Hope that you got your problem solved. |
…eact-navigation#331) * add jest config for react-navigation in docs (react-navigation#256) * Docs: Update redux-integration guide react-navigation#246
After a lot of tries (yes, I've tried everything listed before this comment) I solved this problem by create a manual mock for NavigationService.js. Just follow this question on stackoverflow You're welcome |
Hello,
I'm working with react-native and when I run the basic
index.android.js
test file, it systematically fails with the following:It looks like I'm doing something wrong, but I can't figure out what. I've tried fiddling around with it (mostly changing variables name), but I keep getting the same error.
The application works though, it doesn't show any error. It is the simpliest navigation app I could make, following the react-navigation doc, using redux.
I was wondering if this happened to anyone else, or if anyone has a clue of the dumb mistake I made.
The text was updated successfully, but these errors were encountered: