gpt4 book ai didi

react-native - ReactNative 0.48 上的开 Jest 错误 "Cannot read property ' validAttributes' of undefined"

转载 作者:行者123 更新时间:2023-12-04 04:16:49 28 4
gpt4 key购买 nike

我们最近将一个应用程序从 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>

最佳答案

我花了很长时间,但我终于弄明白是怎么回事了。基本上,我想的更多的测试是渲染动画 View 。我最初将 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
}

现在我的错误消失了!

关于react-native - ReactNative 0.48 上的开 Jest 错误 "Cannot read property ' validAttributes' of undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46432694/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com