Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.
This repository was archived by the owner on Jul 30, 2020. It is now read-only.

Cannot find module 'ReactNative' from 'mock-modules.js' with jest-expo #48

Closed
@marsinearth

Description

@marsinearth

Relevant code or config:

// jest.config.js
const expoPreset = require('jest-expo/jest-preset');
const jestPreset = require('@testing-library/react-native/jest-preset');

module.exports = Object.assign(expoPreset, jestPreset, {
  preset: '@testing-library/react-native',
  transform: {
    '^.+\\.js$': 'babel-jest',
    '^.+\\.tsx?$': 'ts-jest',
  },
  testMatch: [
    '**/__tests__/**/*.ts?(x)',
    '**/?(*.)+(spec|test).ts?(x)',
  ],
  moduleFileExtensions: [
    'js',
    'ts',
    'tsx',
  ],
  globals: {
    'ts-jest': {
      tsConfig: {
        jsx: 'react',
      },
      diagnostics: false,
    },
  },
  modulePathIgnorePatterns: [
    '<rootDir>/build/',
    '<rootDir>/node_modules/',
    '<rootDir>/.history/',
  ],
  setupFiles: [...expoPreset.setupFiles, ...jestPreset.setupFiles, '<rootDir>/test/jestSetup.ts'], // jestSetup.ts is an empty script.
});

What you did:

I followed the installation guide and figured out that the v^33.0.2 jest-expo doesn't contain jest-preset.json as the guide indicates, but instead jest-preset.js. Anyway I imported it as const expoPreset = require('jest-expo/jest-preset'); as in the above snippet.

What happened:

then I tried to test a script, I get this:

$ node node_modules/jest/bin/jest.js src/components/screen/__tests__/Setting.test.tsx
 FAIL  src/components/screen/__tests__/Setting.test.tsx
  ● Test suite failed to run

    Cannot find module 'ReactNative' from 'mock-modules.js'

    However, Jest was able to find:
        './mock-modules.js'

    You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'ts', 'tsx'].

    See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:230:17)
      at Object.<anonymous> (node_modules/@testing-library/react-native/dist/preset/mock-modules.js:18:6)

Reproduction:

https://github.com/marsinearth/native-testing-library-issue-repro

Problem description:

I think something between jest-expo and native-testing-library has been compromised by changed structure of jest-expo package.

Suggested solution:

the error log is very limited, nor I know how to access more log. perdóname.

Can you help us fix this issue by submitting a pull request?

I wish...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions