Skip to content
Advertisement

Jest testcase breaking in React Native Expo

Following is the error I receive on running a Sample testcase:

Expected react-native/jest-preset to define transform[^.+.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$]
react-native/jest-preset contained different transformIgnorePatterns than expected
 FAIL  ./App.test.js
  ● Test suite failed to run

    Cannot find module 'react-native/Libraries/LogBox/LogBox' from 'setup.js'

      at Resolver.resolveModule (node_modules/jest-expo/node_modules/jest-resolve/build/index.js:299:11)
      at Object.<anonymous> (node_modules/jest-expo/src/preset/setup.js:155:6)

My Testcase:

import React from 'react';
import renderer from 'react-test-renderer';

import App from './App';

describe('<App />', () => {
  it('has 1 child', () => {
    const tree = renderer.create(<App />).toJSON();
    expect(tree.children.length).toBe(1);
  });
});

My jest configuration in package.json:

"jest": {
    "preset": "jest-expo",
    "transformIgnorePatterns": [
      "<rootDir>/node_modules/(?!(jest-)?react-native|react-clone-referenced-element|@react-native-community|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|@sentry/.*)",
      "node_modules/(?!(react-native|my-project|react-native-button)/)"
    ]
  },

My dependencies in package.json:

    "jest": "^26.4.2",
    "jest-expo": "^39.0.0",
    "jest-react-native": "^18.0.0",
    "react-test-renderer": "^16.13.1",

expo version: 37.0.0

react: `16.9.0

react-native: "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz"

Advertisement

Answer

Found the solution on the Expo thread mentioning the exact same issue here.

It looks like you’re using jest-expo v39 with a project running SDK37. LogBox was released with React Native 0.63 which is what SDK39 is using. Can you try running with v37.0.0 and see if that resolves the issue?

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement