Trying to get Jest v12.1.1 by working with React Native v0.26.2. I get this error when running npm test : Error: Cannot find module 'ErrorUtils' from 'env.js'
Here is my package.json . I am trying to get this to work with the react-native init AwesomeProject starter.
Is there anything in my .json package? (are there no lines here that I don't need?)
EXAMPLE 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 } }
This is where the test script runs.
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); }); });
EXAMPLE 2:
I get another error when I add haste to package.json and scriptPreprocessor and setupEnvScriptFile . Error: Cannot find module 'AwesomeProject' from 'index.android-test.js'
I have no clue why I'm moving forward. My previous example 1 is as follows: https://facebook.imtqy.com/jest/docs/tutorial-react.html#content And example 2 with "haste": https://github.com/fbsamples/f8app/blob/master /package.json
It is actually unclear why Ex 1 is not working.
fixed 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 } }