Skip to content

Cannot import a jest.mock() when running tests with --coverage #583

Closed
jestjs/jest
#1754
@gaelollivier

Description

@gaelollivier

Steps:

  • Create a new app: create-react-app my-app
  • Create a new file that does a jest.mock(), ex:

src/mock.js

jest.mock('react-dom', () => {})
  • Import this file in App.test.js:

src/App.test.js

import './mock.js'

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
...
  • Run the tests with --coverage:
npm run test -- --coverage

I get this error:
image

I can't find a workaround for this, there's no documentation on how to import mocks so I can reuse them.

@cpojer It may be a Jest issue ? Am I doing something wrong ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions