Ever since upgrading to Jest 26 & Angular 10, the unit test error line numbers are incorrectly reported. I have Been using Jest since Angular 4 and have upgraded with each new version.
I have read through every existing article on this and tried every suggestion I can find. None of them appear to work for my situation.
I have been able to create a minimum repo where you can see this happening (https://github.com/russcarver/angular-jest-test/tree/jest-line-errors). Be sure you're on the jest-line-errors
branch. I've added comments to the app.component.spec.ts file (https://github.com/russcarver/angular-jest-test/blob/jest-line-errors/src/app/app.component.spec.ts) to show the issues.
The first one, oddly, is that I have to add a "dummy" test to the top of each spec file. Otherwise, the first test always fails in each file:
it('Should init the Test Suite', noop); // ****** The first test fails unless I add this ******
I created this solution out of desperation when nothing else would work. I have a hunch it's related.
This particular Angular upgrade also recommended splitting out the tsconfig.json file into tsconfig.base.json, tsconfig.app.json and tsconfig.spec.json.
When I change various options in tsconfig.spec.json, the error-line-numbers do change (specifically with the lib
, module
and target
options). I have paired down this file to the minimum I need for my (large) project and have modified it in the repo to NOT extend tsconfig.base.json. I have also research and set the options to what I believe to be the best for my project (which targets the latest 2 versions of Chrome, Edge Safari & FireFox and uses all the latest JavaScript and TypeScript features).
I know it's not an Angular issue as I've been able to reproduce this with Angular 9, 10 and 11. Before all the tsconfig changes, it used to work in Angular 9 & Jest 25.
I also know (have tested) that it's not related to blank lines or comments in the spec files.
I have also tried a Babel configuration to no avail.
I used to use jest-preset-angular
(which is now deprecated) but adding/removing that makes no difference.
Line number are incorrectly reported whether or not coverage is enabled/run.
We've been suffering through this since last July (2020). Any help would be greatly appreciated!