question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Code coverage tool (jest --coverage) not recognizing coverage for rewired functions (jest @23.4.2, rewire @4.0.1)

See original GitHub issue

Hello !

So, first of all, I love rewire. Being able to just test specific functions without having to export them all is great. Thank you !

On to the issue. We recently migrated from mocha to Jest, and it seems that when it comes to coverage jest has an issue with rewire, or rewire an issue with jest.

Trying to get a specific function, like this

const myModule = rewire("./path/to/module"); const myFunction = myModule.__get__("myFunction");

Then testing it, like so

`describe(“Simple function test”, function () { let input = “hey !”; let expectedResult = “hello !”; let result = () => myFunction(input);

	it("should not throw an error", () => {
		return expect(result).not.toThrow();
	});
	
	it("should return the expected result", () => {
		return expect(result()).toStrictEqual(expectedResult);
	});
});`

Ends up running the tests properly (checked with breakpoints that everything passed where it should), but the function is not considered as covered in the coverage report 😢

I’ll put together a minimal repo to demonstrate it, either this evening or by the end of next week.

A great week-end to all of those who read this ! 😃

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:26
  • Comments:20

github_iconTop GitHub Comments

6reactions
OrBarak1990commented, Aug 25, 2019

Also in my case, any new? or some kind of a workaround?

6reactions
Cosmo439commented, Mar 22, 2019

Any movement on this issue? I’ve got the same problem as well jest: 24.5.0 and rewire: 4.0.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest coverage test does not include 'rewired' files
I am including my non-exported function (let's say A) to the Jest unit tests with the 'rewire' function. When I run the coverage...
Read more >
rewire - Bountysource
Code coverage tool (jest --coverage) not recognizing coverage for rewired functions (jest @23.4.2, rewire @4.0.1) $ 0. Created 4 years ago in jhnns/ ......
Read more >
Configuring code coverage in Jest, the right way
In this brief tutorial we see how to configure code coverage for Jest, the right way.
Read more >
Running tests and creating code coverage reports for React ...
The Jest-JUnit integration with Jenkins lacks some functionality, but it doesn't require installing the Cobertura Jenkins Plugin (for example if its license is ......
Read more >
Tracking frontend coverage of your e2e tests with Playwright
Overview and setup guide for tracking and visualizing the JavaScript test coverage of your Playwright end-to-end tests with Jest.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found