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.

Reanimated 2.5.0 break Jest test

See original GitHub issue

Description

Run jest test with Reanimated 2.5.0. Test break with following error:

  ● Test suite failed to run

    TypeError: ReanimatedModule.installTurboModule is not a function

      at new NativeReanimated (node_modules/react-native-reanimated/lib/reanimated2/NativeReanimated/NativeReanimated.js:6:98)
      at JSReanimated._createSuperInternal (node_modules/react-native-reanimated/lib/reanimated2/js-reanimated/JSReanimated.js:32:311)
      at new JSReanimated (node_modules/react-native-reanimated/lib/reanimated2/js-reanimated/JSReanimated.js:8:9)
      at Object.<anonymous> (node_modules/react-native-reanimated/lib/reanimated2/js-reanimated/index.js:3:22)
      at Object.<anonymous> (node_modules/react-native-reanimated/lib/reanimated2/NativeReanimated/index.js:1:1)


Expected behavior

Test pass as before

Actual behavior & steps to reproduce

  • Create a new RN app with 0.67.4 and Reanimated 2.5.0 and Jest.
  • Write an example test.
  • run yarn test then example test will fall

Snack or minimal code example

As mentioned above, an example project with jest will work

Package versions

name version
react-native 0.67.4
react-native-reanimated 2.5.0
NodeJS
Xcode
Java
Gradle
expo

Affected platforms

  • Android
  • iOS
  • Web

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:7
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

40reactions
AlexanderEggerscommented, Apr 1, 2022

I fixed the issue by updating my project’s jest-setup.js:

global.__reanimatedWorkletInit = () => {}
jest.mock('react-native-reanimated', () => require('react-native-reanimated/mock'))
16reactions
wbinarytreecommented, Apr 1, 2022

I added this code to fix the error above. But seems there is another issue occurs: code :

diff --git a/node_modules/react-native-reanimated/lib/reanimated2/NativeReanimated/NativeReanimated.js b/node_modules/react-native-reanimated/lib/reanimated2/NativeReanimated/NativeReanimated.js
index 92d53ef..6b4bf86 100644
--- a/node_modules/react-native-reanimated/lib/reanimated2/NativeReanimated/NativeReanimated.js
+++ b/node_modules/react-native-reanimated/lib/reanimated2/NativeReanimated/NativeReanimated.js
@@ -1,8 +1,11 @@
 import { NativeModules } from 'react-native';
+import { isJest } from '../PlatformChecker';
+
 export class NativeReanimated {
     constructor(native = true) {
-        if (global.__reanimatedModuleProxy === undefined) {
+        if (global.__reanimatedModuleProxy === undefined && !isJest()) {
             const { ReanimatedModule } = NativeModules;
+            console.log("native module:" , ReanimatedModule)
             ReanimatedModule === null || ReanimatedModule === void 0 ? void 0 : ReanimatedModule.installTurboModule();
         }
         this.InnerNativeModule = global.__reanimatedModuleProxy;
    TypeError: Cannot read properties of undefined (reading 'now')

      at Object.now (node_modules/react-native-reanimated/lib/reanimated2/js-reanimated/JSReanimated.js:14:72)
      at JSReanimated.getTimestamp (node_modules/react-native-reanimated/lib/reanimated2/js-reanimated/JSReanimated.js:25:34)
      at Timeout._onTimeout (node_modules/react-native-reanimated/lib/reanimated2/js-reanimated/JSReanimated.js:32:37)

The reading 'now' issue resolved by this fix:

// add into jest.config
global.ReanimatedDataMock = {
  now: () => 0,
};

after comparing code 2.4.1 and 2.5.0. I think those 2 are bugs introduced by 2.5.0. Do we plan to have a fix?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing with Jest | React Native Reanimated - Software Mansion
Testing with Jest. Reanimated test mocks use web implementation of Reanimated2. Before you begin using Reanimated mocks you need some setup actions.
Read more >
Npm libraries not working in React Native - Stack Overflow
Perform the Below steps: delete node_modules folder; delete package-lock.json file; install new version of dev Dependencies. npm install.
Read more >
react-native-reanimated:buildcmakedebug - You.com | The search ...
You.com is an ad-free, private search engine that you control. Customize search results with 150 apps alongside web results. Access a zero-trace private ......
Read more >
react-native-navigation | Yarn - Package Manager
This is not a breaking change and is done in preparation to deprecate the bottomTabs.drawBehind option on iOS. Deprecate registerComponentWithRedux.
Read more >
Twitter \ التغريدات مع الردود بواسطة React Native UI Lib (rnuilib@)
Turning up reanimated's benchmarks to test the new shared value implementation and it does not even sweat maintaining steady 60fps while the old...
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