2016-08-22 25 views
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"] 
} 

回答

0

我有你正在使用玩笑的错误版本的感觉。您有:

"jest": "^14.1.0", 
"jest-cli": "^13.1.0" 

但似乎使用npm -g13.2.3安装:

Using Jest CLI v13.2.3, jasmine2, babel-jest 

首先,我想你可以删除jest-cli,只是使用jest 14.1.0

"scripts": { 
    "test": "./node_modules/jest/bin/jest.js" 
} 

这样,你要确保你运行你的项目的本地玩笑副本,所以现在应该说:

然后,像您可以更新test脚本

Using Jest CLI v14.1.0, jasmine2, babel-jest 

这样做,并遵循你发布的官方docs,它应该是你需要的一切(不能肯定地说,因为你没有发布测试代码)。

+0

感谢您的回复。它似乎开玩笑被安装在我的缓存或什么..我更新到这个: “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

+0

顺便说一下,https://facebook.github.io/jest/docs/troubleshooting.html#caching-issues。所以你也可以试试'jest --no-cache'。 –