6

我正在使用 React Native(版本 0.59.10)构建一个项目。每当我运行测试(使用 Jest)时,我都会收到以下警告:

    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

这似乎是由于“react-native-elements”又使用了Animatedin TouchableOpacitywhich 。Button

用 Xcode 查看我的项目,我可以看到该RCNativeAnimation项目在那里:

来自 Xcode 的屏幕快照显示 RCNativeAnimation 存在

我检查了引用的链接:https ://github.com/facebook/react-native/issues/11094#issuecomment-263240420但它已经很老了,并且指的是 React Native 和 Xcode 的非常旧的版本。

我猜这个警告只是与RCNativeAnimation无法从测试中访问的本机模块有关,但我不知道如何useNativeDriver在测试上下文中“删除”。显然,在真正的应用程序中,我想确保我使用的是本机动画库,但在单元测试中我不在乎。

消除此警告的推荐方法是什么?

4

2 回答 2

3

change the jest.mock to:

jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
于 2019-12-17T12:21:14.160 回答
1

添加jest.mock('NativeAnimatedHelper');到您的测试文件

于 2019-07-12T02:35:20.387 回答