-
Notifications
You must be signed in to change notification settings - Fork 453
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
Need help with code coverage when using Jest to test Angular app #454
Comments
@AhnpGit I'll try to take a look at this after work today |
@AhnpGit I tested this and saw the issue you've stated. However, I'm not sure what the cause of this is. Also, while I use angular and I use ts-jest, I don't use ts-jest with angular so I'm not very familiar with the preset. As ts-jest doesn't handle coverage at all (it's handled in jest), I'm not sure there's anything that can be done here to fix this. |
The preset was created by @thymikee and he refused ts-jest in the precessor. Probably I need to debug jest coverage. Btw, is the runner jest-runner-tsc does the same thing as ts-jest ? |
@AhnpGit can you test this with Jest master? We recently merged this: jestjs/jest#5692 |
Sure i'll check. I saw that change in master yesterday but I didn't understand quite well what it can help |
Ah, forgot we use TS for JS files too, so that shouldn't change anything. |
I suppose I need to debug jest coverage then :) |
@kulshekhar I just found out something suspicious about Angular itself. If I write test for a normal ts file, coverage is always correct no matter how many things I define in the constructor of the ts class. However, when adding Angular decorator @component, the coverage immediately goes wrong on the constructor. Do you think this might cause by TypeScript decorator or Angular itself ? |
@AhnpGit |
@kulshekhar you were right. I found out indeed it was caused by Angular DI. DI uses TypeScript feature I haven't tried to create a decorator with reflect meta yet to test but I think it will have the same issue. I still don't know what should be the proper fix, but I guess something for Jest I assume. @thymikee do you think so ? |
@AhnpGit can you check whether v22.4.4 fixes this for you? |
@kulshekhar it seems to not working for me |
Have you also set the ignore decorator flags? You can view them either in the readme or the changed files inside PR #488 |
Yes I tried, but none of them works for decorators which are created by Angular. |
@ahnpnl lemme know if 23.10 doesn't fix this ;-) |
[email protected] |
@danil-z 23.10.3 is out, use it instead it should fix your issue |
Still experiencing the same with ts-jest 23.10.3 and jest 23.6.0. Cleared the cache before running the tests. |
@blackholegalaxy please provide a minimal repo to reproduce and, since this issue is old and not opened by you, explain the exact problem which you personally have in this repo ;-) |
package.json
test.tsconfig.json
libs/packages
|
problem remains, can be reproduced on any sample project with angular |
here is repo to reproduce |
I tried to use Jest to test Angular app but the code coverage shows branch not covered for dependency injection in constructor. This issue is fixed if using Karma + Jasmine with Angular CLI. I hope someone can help me to point out what goes wrong, either in ts-jest or Jest
Expected behavior
Code coverage should show correctly
Output from your debug log
N.A
Link to a minimal repo that reproduces this issue
https://github.com/AhnpGit/coverage-issue-jest
Run
yarn coverage
and check coverage of app.component.ts. It shows yellow on dependency injection in constructorcc @kulshekhar
The text was updated successfully, but these errors were encountered: