我正嘗試使用酶來測試我的React Native項目,並遵循了設置說明。如何在使用第三方模塊時未測試項目時測試項目
https://github.com/airbnb/enzyme/blob/master/docs/guides/react-native.md
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "mocha --require react-native-mock/mock.js --compilers js:babel-core/register --recursive test/**/*.js"
},
能正常工作和我自己的代碼是否正確transpiled,但是當我包括不transpile他們的代碼(例如https://github.com/aksonov/react-native-router-flux)一個模塊,我的測試拒絕,因爲它的誤差在運行這些模塊中的導入語句。
如何讓babel transpile這些模塊或有另一種方式讓我的測試運行?
更新
看來,非transpiled第三方模塊是相當普遍與之反應,因爲原住民土著做出反應本身並不transpiled。
該解決方案似乎確實是強制轉譯和使用react-native-mock的組合。 https://github.com/facebook/react-native/issues/5392
但是,由於NavigationExperimental沒有被模擬,我還遇到了與react-native-router-flux有關的其他問題。
相關鏈接:
https://github.com/lelandrichardson/react-native-mock/issues/23 https://github.com/lelandrichardson/react-native-mock/issues/22 https://github.com/lelandrichardson/react-native-mock/pull/34
我會更新在這裏,如果我找到一個解決方案。
更新2
我已經包含下面我目前的解決方法的情況下,任何人發現它是有用的。
https://stackoverflow.com/a/37655424/168012
安裝'反應本地路由器-flux'從NPM?這不是ES5? – JMM
@JMM是的。我不得不再次檢查,因爲我現在正在直接從分支中提取,但是從NPM安裝的是ES6。最近一次公關變革被放棄了,所以我正在尋找替代解決方案https://github.com/aksonov/react-native-router-flux/pull/649 – Tom