question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jest: global.__reanimatedWorkletInit is not a function

See original GitHub issue

Description

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:

Screenshot 2020-10-26 at 10 19 09

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

  1. Install reanimated v2
  2. Create some complex tests
  3. 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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

29reactions
M-i-k-e-lcommented, Jun 21, 2021

What worked for us was adding the following to the jest-setup.js file:

global.__reanimatedWorkletInit = jest.fn();
5reactions
nandorojocommented, Apr 28, 2022

It looks like Reanimated 2.8 is breaking on Next.js, throwing this error:

Screen Shot 2022-04-28 at 5 13 57 PM
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found