-
Notifications
You must be signed in to change notification settings - Fork 128
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
Code coverage tool (jest --coverage) not recognizing coverage for rewired functions (jest @23.4.2, rewire @4.0.1) #145
Comments
Ran into the same issue with latest Here's the demo repo showing the issue, simple |
Rewire is amazing for testing our non-module code, but sadly I am having this issue as well. |
😢 Did this work for anyone? I am on
and my tests run correctly but coverage is 0% babel.config.js
|
I am also hitting the same issue |
Looking for some alternative here because I've fallen in the same place as cited above, but I'd love to keep with |
I've just realized that any // module.js
const rawFs = require('fs');
class Module {
constructor(fs){
this.fs = fs || rawFs;
}
doSomething(filepath){
const file = this.fs.readFileSync(filepath, 'utf-8');
...
}
}
module.exports = Module; So, mocking becomes a breeze... // module.test.js
const Module = require('./module');
describe('Module File', () => {
it('should so something', () => {
const fsMock = { readFileSync: jest.fn() };
const filepath = 'some/path/to/file.js';
const module = new Module(fsMock);
module.doSomething(filepath);
expect(fsMock.readFileSync).toHaveBeenCalledWith(filepath, 'utf-8');
});
}) |
Any movement on this issue? I've got the same problem as well |
Rewire is great but not being able to provide code coverage details is a major blocker for us. Would love to see coverage added to this library. Current jest version is 23.6.0 and the version of rewire out team tried out was 4.0.0 |
I have the same issue. Any updates? |
Also in my case, any new? or some kind of a workaround? |
I'm running into the same issue and its approaching 1-1/2 years unresolved? Like the other commenters, I really like rewire, but I'm wondering if I should abandon it before I get too dependent on it? |
+1 |
Any update on this? |
Same issue today : code coverage don't count rewires calls for internal (unexported) tests.
|
I'am facing the same issue:
|
Same issue :/ |
+1
|
+1 |
Found a temp solution: https://www.grzegorowski.com/jest-tests-with-rewire-plugin |
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);
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 ! :-)
The text was updated successfully, but these errors were encountered: