-
Notifications
You must be signed in to change notification settings - Fork 455
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
Should this work with react native? #92
Comments
I don't have any experience with react-native so I'm not sure what's going on. Would it be possible for you to create a minimal repo that reproduces this issue? |
I think react native uses babel internally. That lead me into trying this to enable es6. That makes it get further and even can run some tests. However react-test-renderer still doesn't work with this method - making snapshot tests impossible. That's especially annoying because snapshot testing is annoying if you have a build folder that isn't in version control - jest will place all it's snapshot files in the temporary build folder. If I learn anything more I'll post here. |
|
The root cause of this issue is the use of trailing commas in function calls in Trailing commas in function calls aren't natively supported in node yet. Preprocessing such files with babel/typescript takes care of this issue. However, since these files are added as part of a dependency, I'd expect them to be installed in a form that node can understand. That aside, I have no idea why |
I managed to make it work, install these modules:
Create a .babelrc file with this content: {
"presets": ["react-native"]
} And finally in package.json, use this transform: "transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
} |
@FMatosS where you able to run the home component test from the example repo? I've found a few solutions that will run non react related tests but nothing that works with react-test-renderer. Either renderer becomes undefined or in the case of your suggestion I get
I suspect there is some complex babel work being done by react native's tooling that is hard to mimic. If I compile the typescript first and then test it works fine. |
Sorry here is the correct error - before I forgot about babelrc. This is consistent with other attempts I made messing with babel.
I updated the repo to show this. |
Apply this patch using git apply: https://gist.github.com/fmatoss/34d57f5bc70f64dac6f67a97f5b8b050 I made some small changes, since TypeScript 2.0, using @types scope is the preferred way to include declaration files. |
Cool that works thank you @FMatosS So I guess the answer to can ts-jest work with react-native is yes but with some changes. As far as I can tell that includes
|
I think this one is not related to ts-jest, react-test-renderer don't have a default export, the same happens to React, but if you want to import the entire module, this will work for you: import * as renderer from "react-test-renderer"; |
@kulshekhar do you any notes about react native added to the readme? Otherwise this can be closed. |
@kulshekhar Check my PR #95 |
closing following #95 |
I'm using jest and react native. I can test it by manually compiling the typescript into js and running jest on that. Trying to use this project I get
My relevant package.json
I've read through the limitations but those don't seem to apply to me, not targeting ES6 ect. Using node v6.9.2
The text was updated successfully, but these errors were encountered: