我正在使用以下package.json (根据http://facebook.github.io/jest/docs/tutorial-react-native.html#content):
{
"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"]
}发布于 2016-08-23 00:55:18
我有一种感觉,您使用的Jest版本是错误的。您必须:
"jest": "^14.1.0",
"jest-cli": "^13.1.0"但是您似乎已经使用npm -g安装了13.2.3
Using Jest CLI v13.2.3, jasmine2, babel-jest首先,我认为您可以删除jest-cli,只使用jest 14.1.0。
然后,您可以更新test脚本,如下所示:
"scripts": {
"test": "./node_modules/jest/bin/jest.js"
}通过这种方式,您可以确保运行项目的本地Jest副本,因此它现在应该显示:
Using Jest CLI v14.1.0, jasmine2, babel-jest这样做,并遵循您发布的官方docs,它应该是您需要的一切(不能肯定,因为您没有发布测试代码)。
https://stackoverflow.com/questions/39083825
复制相似问题