jest will fail with react-native-reanimated
See original GitHub issueDescription
I created a react-native-library with react-native-reanimated
. Now I’m trying to add tests to my project, but all the tests fail. It complains that Jest encountered an unexpected token.
the full error report is below:
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it.
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
/Users/damon/Documents/thundersdata/frontend/rn-template/node_modules/react-native-reanimated/mock.js:71
return <Component {...this.props} />;
^
SyntaxError: Unexpected token '<'
2 | jest.mock('react-native-reanimated', () => {
3 | // eslint-disable-next-line @typescript-eslint/no-var-requires
> 4 | const Reanimated = require('react-native-reanimated/mock');
| ^
5 |
6 | // The mock for `call` immediately calls the callback which is incorrect
7 | // So we override it with a no-op
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
at jest/setup.js:4:22
at Object.<anonymous> (node_modules/@td-design/react-native/src/accordion/Panel.tsx:3:1)
Screenshots
steps to reproduce
Expected behavior
I should run all the tests successfully.
Actual behavior
it fails.
Snack or minimal code example
you can clone my project here: https://github.com/thundersdata-frontend/rn-template
Package versions
- React: v17.0.1
- React Native: v0.63.4
- React Native Reanimated: 1.13.2
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Testing with Jest | React Native Reanimated - Software Mansion
Reanimated test mocks use web implementation of Reanimated2. Before you begin using Reanimated mocks you need some setup actions.
Read more >"TypeError" when trying to render react-native-reanimated ...
What is particularly strange here is that I am not directly using react-native-reanimated in my code base, and the only library components I...
Read more >Testing with Jest - React Navigation
Testing with Jest. Testing code using React Navigation takes some setup since we need to mock some native dependencies used in the navigators....
Read more >TypeError" when trying to render react-native-reanimated ...
Coding example for the question "TypeError" when trying to render react-native-reanimated node in Jest test-React Native.
Read more >failed to initialize react-native-reanimated library - You.com
config.js (you should have 'react-native-reanimated/plugin' listed there - also see the aboveisted there ...
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
This is a problem with your jest config, I managed to get your repository to work with that patch:
This is related to Jest not transforming
node_modules/
.@jakub-gonet Thank you so much! You saved my day!