Can't get Jest & React Native to work

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 } } 
+2
react-native jestjs babel-jest
source share

No one has answered this question yet.

See similar questions:

7
React Native - __DEV__ is undefined

or similar:

6
Jest TransformIgnorePatterns all node_modules for React-Native Preset
5
React Native + Jest EMFILE: Too Many Open File Errors
3
Configuring Jest and Enzyme to test React 15 cannot find reaction module / lib / ReactTestUtils
2
Error errors without .babelrc. Respond to it.
2
Error: Failed to resolve the reaction-reduction module / native
2
Unable to import Expo from 'Expo'. in native reaction
one
Jest tests continue to fail
one
How to resolve a React Native warning message
one
why the reaction-native run command is stuck on "Loading dependency graph".
0
Jest discovered an unexpected token with a reaction

All Articles