Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native (0.59.10) — How do I remove `useNativeDriver` when running tests (but not in the actual app)

I am building a project with React Native (version 0.59.10). Whenever I run my tests (using Jest) I get this warning:

    console.warn node_modules/react-native/Libraries/Animated/src/NativeAnimatedHelper.js:248
      Animated: `useNativeDriver` is not supported because the native animated module is missing. Falling back to JS-based animation. To resolve this, add `RCTAnimation` module to this app, or remove `useNativeDriver`. More info: https://github.com/facebook/react-native/issues/11094#issuecomment-263240420

This seems to be due to the use of Animated in TouchableOpacity which is in turn used by Button from 'react-native-elements'.

Looking into my project with Xcode I can see that the RCNativeAnimation project is there:

screen snap from Xcode showing RCNativeAnimation exists

I checked the referenced link: https://github.com/facebook/react-native/issues/11094#issuecomment-263240420 but that is ages old and refers to very old versions of both React Native and Xcode.

I am guessing this warning is just related to the native RCNativeAnimation module not being accessible from the tests but I am at a loss as to how to 'remove useNativeDriver' within the test context. Obviously in the real app I want to ensure I am using the native animation libraries, but in the unit tests I don't care.

What is the recommended way to eliminate this warning?

like image 557
Dave Sag Avatar asked Jul 05 '19 05:07

Dave Sag


1 Answers

change the jest.mock to:

jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
like image 61
Mario Elorza Avatar answered Sep 17 '22 07:09

Mario Elorza