Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gaelollivier opened this issue Sep 5, 2016 · 5 comments · Fixed by jestjs/jest#1754
Closed

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

gaelollivier opened this issue Sep 5, 2016 · 5 comments · Fixed by jestjs/jest#1754

Comments

@gaelollivier
Copy link
Contributor

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 ?

@gaearon
Copy link
Contributor

gaearon commented Sep 5, 2016

Not sure if bug or not but we tagging this as something to fix.

@cpojer
Copy link
Contributor

cpojer commented Sep 5, 2016

this is definitely a Jest bug. We'll fix it.

@gaelollivier
Copy link
Contributor Author

Any idea on how to workaround this until it's fixed ? I can't figure out how to reuse my mocks in create-react-app right now

@gaearon
Copy link
Contributor

gaearon commented Sep 18, 2016

Moving the milestone because I want to release 0.4.2 today, and this is not fixed yet.
@cpojer Could you provide any estimate on this?

@gaearon gaearon modified the milestones: 0.4.3, 0.4.2, 0.4.4 Sep 18, 2016
@cpojer
Copy link
Contributor

cpojer commented Sep 21, 2016

We'll publish a fix with Jest 16 likely later this week.

@gaearon gaearon modified the milestones: 0.5.0, 0.4.4 Sep 21, 2016
@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants