Cannot import a jest.mock() when running tests with --coverage
See original GitHub issueSteps:
- 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:
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 ?
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Jest mock not covering function or returning error
Here is the unit test solution: api.js : const csv = require('csvtojson'); const request = require('request'); export const getApiData = url ...
Read more >The module factory of `jest.mock()` is not allowed to ... - GitHub
I'm using the snippet from #1960 to mock Picker in RN import React, {Component} from 'react'; jest.mock(`Picker`, () => { // ...etc }) ......
Read more >How to mock imported functions with Jest - DEV Community
To mock an imported function with Jest we use the jest.mock() function. jest.mock() is called with one required argument - the import path...
Read more >Configuring Jest
This option tells Jest that all imported modules in your tests should be mocked automatically. All modules used in your tests will have...
Read more >Unit testing | single-spa
This is necessary because the test environment cannot dynamically import ... Create a jest config file; Setup a mocks directory at the root;...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We’ll publish a fix with Jest 16 likely later this week.
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?