尝试让Jest v12.1.1与React Native v0.26.2一起使用我在运行npm test
时遇到此错误:
Error: Cannot find module 'ErrorUtils' from 'env.js'
这是我的package.json
。我尝试使用默认的react-native init AwesomeProject
启动器。
我的package.json中缺少什么东西? (这里有什么线路我不需要?)
示例1:
的package.json
{
"name": "AwesomeProject",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
},
"dependencies": {
"react": "^15.0.2",
"react-native": "^0.26.2"
},
"devDependencies": {
"babel-jest": "^9.0.0",
"babel-preset-es2015": "*",
"babel-preset-react": "*",
"jest-cli": "^12.1.1"
},
"scripts": {
"test": "jest"
},
"jest": {
"scriptPreprocessor": "node_modules/react-native/jestSupport/preprocessor.js",
"setupEnvScriptFile": "node_modules/react-native/jestSupport/env.js",
"testPathIgnorePatterns": [
"/node_modules/",
"/android/",
"/ios/",
"/.idea/"
],
"testFileExtensions": [
"js"
],
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/react/",
"<rootDir>/node_modules/react-dom/",
"<rootDir>/node_modules/react-addons-test-utils/"
],
"verbose": true
}
}
这是一个测试脚本。
index.android-test.js
// __tests__/index.android-test.js
'use strict';
jest
.disableAutomock()
.setMock('AwesomeProject', {})
.setMock('React', {Component: class {}});
describe('AwesomeProject', () => {
it('test something', () => {
const testJunk = true;
expect(testJunk).toEqual(true);
});
});
示例2:
当我添加&#34;急速&#34;时,我收到了不同的错误到package.json
并删除scriptPreprocessor
&amp; setupEnvScriptFile
。
Error: Cannot find module 'AwesomeProject' from 'index.android-test.js'
我不知道为什么我会更进一步以下。我之前的示例1如下: https://facebook.github.io/jest/docs/tutorial-react.html#content 以及&#39; haste`的示例2如下: https://github.com/fbsamples/f8app/blob/master/package.json
真的很困惑为什么Ex 1不起作用。
修订了package.json
{
"name": "AwesomeProject",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
},
"dependencies": {
"react": "^15.0.2",
"react-native": "^0.26.2"
},
"devDependencies": {
"babel-jest": "^9.0.0",
"babel-preset-es2015": "*",
"babel-preset-react": "*",
"jest-cli": "^12.1.1"
},
"scripts": {
"test": "jest"
},
"jest": {
"haste": {
"defaultPlatform": "android",
"platforms": [
"ios",
"android"
],
"providesModuleNodeModules": [
"react-native"
]
},
"testPathIgnorePatterns": [
"/node_modules/",
"/android/",
"/ios/",
"/.idea/"
],
"testFileExtensions": [
"js"
],
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/react/",
"<rootDir>/node_modules/react-dom/",
"<rootDir>/node_modules/react-addons-test-utils/"
],
"verbose": true
}
}