Skip to content
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

ng test --code-coverage fails (while "ng test" is ok) #460

Open
ddzingielewski opened this issue Dec 15, 2021 · 4 comments
Open

ng test --code-coverage fails (while "ng test" is ok) #460

ddzingielewski opened this issue Dec 15, 2021 · 4 comments

Comments

@ddzingielewski
Copy link

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

@cofad
Copy link

cofad commented Dec 27, 2021

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.

@jginsburgn
Copy link
Member

Could you provide repro steps?

@ddzingielewski
Copy link
Author

Could you provide repro steps?

To Reproduce:

  1. git clone https://github.com/swimlane/ngx-charts.git
  2. mark "fdescribe" on (for example) line-chart.component.spec.ts line no 5:
  3. run "ng test"
  4. run "ng test --code-coverage"

@jhnielsen
Copy link

jhnielsen commented May 12, 2022

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);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants