我们最近从ReactNative 0.42更新到0.48。在该更新中,我们迁移到Jest进行测试(来自mocha / chai / enzyme)。我们目前正在使用Jest v21.1.0。当我手动运行每个测试时,它们都会毫无错误地通过。当我只运行yarn jest
时,我收到此错误:
/scratch/react_native_app/client/node_modules/react-native/Libraries/Renderer/ReactNativeStack-dev.js:2582
warnForStyleProps$1(nativeProps,viewConfig.validAttributes);
^
TypeError: Cannot read property 'validAttributes' of undefined
at setNativePropsStack$1 (/scratch/react_native_app/client/node_modules/react-native/Libraries/Renderer/ReactNativeStack-dev.js:2582:43)
at Component.setNativeProps (/scratch/react_native_app/client/node_modules/react-native/Libraries/Renderer/ReactNativeStack-dev.js:2550:1)
at AnimatedProps.callback [as _callback] (/scratch/react_native_app/client/node_modules/react-native/Libraries/Animated/src/AnimatedImplementation.js:1819:20)
at AnimatedProps.update (/scratch/react_native_app/client/node_modules/react-native/Libraries/Animated/src/AnimatedImplementation.js:1698:6)
at /scratch/react_native_app/client/node_modules/react-native/Libraries/Animated/src/AnimatedImplementation.js:230:69
at Set.forEach (native)
at _flush (/scratch/react_native_app/client/node_modules/react-native/Libraries/Animated/src/AnimatedImplementation.js:230:16)
at AnimatedValue._updateValue (/scratch/react_native_app/client/node_modules/react-native/Libraries/Animated/src/AnimatedImplementation.js:939:1)
at TimingAnimation.animation.start._this9._animation [as _onUpdate] (/scratch/react_native_app/client/node_modules/react-native/Libraries/Animated/src/AnimatedImplementation.js:906:8)
at TimingAnimation.onUpdate (/scratch/react_native_app/client/node_modules/react-native/Libraries/Animated/src/AnimatedImplementation.js:345:6)
我无法确定,但我们只有两个处理动画和时间的组件。我们正在使用jest.useFakeTimers();
如果我添加jest.runAllTimers();
,我可以在单个组件上获得错误。组件的计时部分如下所示:
componentDidMount() {
Animated.timing(
this.state.fadeAnim, {
toValue: 1,
delay: 2000
}
).start();
}
并且
<Animated.View style={{ opacity: this.state.fadeAnim }}>
...
</Animated.View>
答案 0 :(得分:1)
花了很长时间,但我终于弄清楚发生了什么。基本上,我认为更多的测试是渲染动画视图。我最初在组件的特定测试中包含了jest.useFakeTimers();
,但之后我将其移到了名为test/jest_setup.js
的安装文件中,然后将其添加到我的package.json
文件中:
"jest": {
"setupFiles": [
"./node_modules/react-native/jest/setup.js",
"./test/jest_setup.js"
],
// rest of jest config
}
现在我的错误消失了!