6

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?

skyboyer
  • 22,209
  • 7
  • 57
  • 64
Dave Sag
  • 13,266
  • 14
  • 86
  • 134

2 Answers2

3

change the jest.mock to:

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

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

  • 3
    When I tried adding this line to my test file, I got an error that says `Cannot find module 'NativeAnimatedHelper' from 'App-test.tsx'`. This is after following the v4 docs on a v0.61.1 RN app where I installed `react-navigation`, `react-native-gesture-handler`, and `react-navigation-stack`, and then ran `pod install` in my `ios` directory. – Saad Oct 06 '19 at 13:18