1
我使用(根据http://facebook.github.io/jest/docs/tutorial-react-native.html#content)以下的package.json:玩笑 - 不明 “预设” - “笑话反应的天然的”
{
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
},
"dependencies": {
"react": "^15.3.1",
"react-native": "0.31.0",
},
"devDependencies": {
"babel-jest": "^14.1.0",
"babel-preset-react-native": "^1.9.0",
"jest": "^14.1.0",
"jest-cli": "^13.1.0",
"jest-react-native": "^14.1.3",
"react-test-renderer": "^15.3.1"
},
"jest": {
"globals": {
"__DEV__": true,
"__RCTProfileIsProfiling": false
},
"preset": "jest-react-native"
}
}
但我得到的错误:
Error: Unknown config option "preset" with value "jest-react-native". This is either a typing error or another user mistake and fixing it will remove this message.
Using Jest CLI v13.2.3, jasmine2, babel-jest
FAIL __tests__/AuthorRequest-test.js (0s)
● Runtime Error
- Error: Cannot find module 'throwOnWrongReactAPI' from 'react-native.js'
at Resolver.resolveModule (node_modules/jest-cli/node_modules/jest-resolve/build/index.js:197:17)
at eval (node_modules/react-native/Libraries/react-native/react-native.js:180:26)
at Object.<anonymous> (node_modules/react-native/Libraries/react-native/react-native.js:189:4)
1 test suite failed, 0 tests passed (0 total in 1 test suite, run time 2.238s)
npm ERR! Test failed. See above for more details.
我.babelrc文件包含:
{
"presets": ["react-native"]
}
感谢您的回复。它似乎开玩笑被安装在我的缓存或什么..我更新到这个: “babel-jest”:“*”, “babel-preset-react-native”:“^ 1.9.0”, “jess -cli“: ”*“, ”开玩笑反应的天然的“: ”*“, ”反应试验渲染器“: ”*“ 和 ”开玩笑“:{ ”全局“:{ “__DEV__”:真 }, “预置”: “开玩笑反应的天然的”, “modulePathIgnorePatterns”:[ “FBJS”, “核心-JS” ] } 使用以下脚本: “clean-all”:“rm -rf node_modules /; rm -f tsconfig.json; npm缓存清理; npm install;“ – Arvind
顺便说一下,https://facebook.github.io/jest/docs/troubleshooting.html#caching-issues。所以你也可以试试'jest --no-cache'。 –