2017-09-26 112 views
3

我們有一個應用程序,我們最近從ReactNative 0.42更新爲0.48。在那次更新中,我們遷移到Jest進行測試(從摩卡/柴/酶)。我們目前正在使用Jest v21.1.0。當我手動運行每個測試時,它們都會毫無錯誤地通過。當我跑得yarn jest我得到這個錯誤:Jest Error「Can not read property'validAttributes'of undefined」on ReactNative 0.48

/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

我有同樣的問題,甚至更令人費解:如果單獨運行(每個文件),測試成功。當我運行'npm run jest'時,我得到了這個錯誤。 – pietro909

+0

@ pietro909上個星期我實際上只是想到了這一點。在 – DaKaZ

回答

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 
    } 

現在我的錯誤都不見了!

+0

以下查看我的回答該解決方案無效。順便說一句,包含jest.useFakeTimers()之間的區別是什麼?並在測試/ jest_setup.js? – Max

相關問題