Dave Sag
Dave Sag

Reputation: 13486

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?

Upvotes: 6

Views: 2335

Answers (2)

Mario Elorza
Mario Elorza

Reputation: 31

change the jest.mock to:

jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');

Upvotes: 3

user3167431
user3167431

Reputation: 11

add jest.mock('NativeAnimatedHelper'); to your test file

Upvotes: 1

Related Questions