Should this work with react native?
See original GitHub issueI’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
/node_modules/react-native/jest/setup.js:40
)
^
SyntaxError: Unexpected token )
at transformAndBuildScript (node_modules/jest-runtime/build/transform.js:320:12)
at handle (node_modules/worker-farm/lib/child/index.js:41:8)
at process.<anonymous> (node_modules/worker-farm/lib/child/index.js:47:3)
at emitTwo (events.js:106:13)
My relevant package.json
"jest": {
"preset": "react-native",
"setupFiles": [
"./jest/setup.js"
],
"transform": {
".(ts|tsx)": "./node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
]
}
I’ve read through the limitations but those don’t seem to apply to me, not targeting ES6 ect. Using node v6.9.2
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:14 (9 by maintainers)
Top Results From Across the Web
Why Use React Native for Your Mobile App? - STX Next
With React Native, you create one codebase that works on both Android and iOS. And it doesn't just “work”—it compiles to native Java...
Read more >Why You Should (or Shouldn't) Use React Native
There's a powerful argument to be made that React Native comes closer to mimicking native apps than any of its current competitors. The...
Read more >React Native: What Is It and When Should You Use It?
React Native is based on React, one of the most popular JavaScript frameworks in the world, so knowledge of JavaScript is essential. Whilst ......
Read more >The Good and the Bad of ReactJS and React Native - AltexSoft
React Native uses ReactJS as the JavaScript library, so it has all its advantages. To create a React Native app across platforms, developers ......
Read more >What is React Native, and when to use it for your mobile App?
React Native is a JavaScript library based on ReactJS, which we use to build mobile apps using iOS and Android platforms. The advantage...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I managed to make it work, install these modules:
Create a .babelrc file with this content:
And finally in package.json, use this transform:
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
import { create } from "react-test-renderer";
not likeimport renderer from "react-test-renderer"
;yarn add -D babel-jest babel-preset-react-native
"presets": ["react-native"]