Jest: global.__reanimatedWorkletInit is not a function
See original GitHub issueDescription
We’ve setup jest to snapshot-test components and functionality. I’ve installed reanimated v2 without problems and all tests ran perfectly. After creating some more complex animations and gestures, I found out that suddenly all tests failed with the same error:
Note that I never touched those components/tests after installing reanimated v2
Unfortunately I have no idea what exactly caused this, since the tests in our master
branch still run successfully, and I also got some smaller animations implemented over there.
Screenshots
Steps To Reproduce
- Install reanimated v2
- Create some complex tests
- Run jest
Expected behavior
My tests should run successfully.
Actual behavior
My tests fail. Even the ones I didn’t touch.
Snack or minimal code example
jest.setup.ts
const mock = jest.requireMock("react-native-reanimated");
jest.mock("react-native-reanimated", () => ({
...mock,
useSharedValue: jest.fn().mockReturnValue(0),
useAnimatedStyle: jest.fn().mockReturnValue({}),
useAnimatedScrollHandler: jest.fn().mockReturnValue({}),
createAnimatedComponent: (component) => jest.fn().mockReturnValue(component),
__reanimatedWorkletInit: jest.fn(),
ScrollView: "ScrollView",
}));
// ...
//@ts-expect-error
global.__reanimatedWorkletInit = jest.fn();
Package versions
- React: 16.13.1
- React Native: 0.63.3
- React Native Reanimated: 2.0.0-alpha.7
- @testing-library/jest-native: 3.4.3
- @testing-library/react-native: 7.0.2
- jest: 26.5.3
- NodeJS: v14.13.1
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:8 (4 by maintainers)
Top Results From Across the Web
TypeError: global.__reanimatedWorkletInit is not a function. (In ...
I am using React Native (not expo). I don't even have reanimated downloaded. I had it downloaded then I removed it and rebuilt...
Read more >global.__reanimatedWorkletInit is not a function. react-native ...
Coding example for the question global.__reanimatedWorkletInit is not a function. react-native-animated v2-React Native.
Read more >Reanimated - Expo Documentation
Reanimated uses React Native APIs that are incompatible with "Remote JS Debugging" for JavaScriptCore. In order to use a debugger with your app...
Read more >Unit tests - Mattermost Developers
Jest and Enzyme are the main framework and testing utilities used in testing ... DO NOT assign a regular mock function. const addUsersToTeam...
Read more >react-native-reanimated: Versions - Openbase
Fix Jest 28+ expect.extend is not a function error by @yusufyildirim in ... Ensure global objects initialization for web by @piaskowyk in ...
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
What worked for us was adding the following to the
jest-setup.js
file:It looks like Reanimated 2.8 is breaking on Next.js, throwing this error: