ng test --code-coverage fails (while "ng test" is ok)
ddzingielewski opened this issue · 4 comments
Hi, during exploration of some third party library (swimlane/ngx-charts) i faced with an issue where command "ng test --code-coverage" fails while at the same time command "ng test" works ok. I raised an issue here swimlane/ngx-charts#1709 hoping that library authors already faced with this, but have no reply so far and to be honest it sounds more like an issue in current karma-coverage. In the above link I provided more details. My dev package.json config is as follow:
"devDependencies": { "@angular-devkit/build-angular": "~12.1.2", "@angular/cli": "~12.1.2", "@angular/compiler-cli": "~12.1.2", "@types/clone": "^2.1.1", "@types/jasmine": "~3.5.0", "@types/jasminewd2": "~2.0.3", "@types/node": "^12.11.1", "clone": "^2.1.2", "codelyzer": "^6.0.2", "jasmine-core": "^3.7.1", "jasmine-spec-reporter": "~5.0.0", "karma": "^6.3.8", "karma-chrome-launcher": "~3.1.0", "karma-coverage": "^2.1.0", "karma-jasmine": "~4.0.0", "karma-jasmine-html-reporter": "^1.5.0", "karma-sonarqube-unit-reporter": "0.0.23", "ng-mocks": "^12.5.0", "protractor": "~7.0.0", "sonar-scanner": "^3.1.0", "ts-node": "~8.3.0", "tslint": "~6.1.0", "typescript": "~4.3.5" }
Thanks in advance for any help with this
best regards
Darek
I have a similar issue where "ng test" will run normally, but "ng test --code-coverage" takes a very long time ~24 hours to run. The issue seems to only affect Windows machines. The Macs that run the tests don't have the same issue.
Could you provide repro steps?
Could you provide repro steps?
To Reproduce:
- git clone https://github.com/swimlane/ngx-charts.git
- mark "fdescribe" on (for example) line-chart.component.spec.ts line no 5:
- run "ng test"
- run "ng test --code-coverage"
I just encountered the same error in a non-public Angular 11 project, i.e., the test passed with ng test
and failed with ng test --code-coverage
.
In my case, the class under test was extending an abstract class without explicitly defining a constructor method.
As a result, mocked members of the base class where undefined
in the derived class.
This Stack Overflow post suggests that the DI mechanism is unaware of the base class which is causing the error.
Based on that post, my workaround was to insert a constructor myself, instead of relying on the default constructor:
@Component({
selector: 'foo',
template: `<p>bar</p>`,
})
export class DerivedComponent extends AbstractBaseComponent {
constructor(someService: SomeService) {
super(someService);
}
}