Code Coverage breaks constructor inheritance
See original GitHub issue🐞 Bug report
Command (mark with an x
)
- [ ] new
- [ ] build
- [ ] serve
- [x] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc
Is this a regression?
Yes, the previous version in which this bug was not present was: 7.2
Description
Running with code coverage enabled breaks constructor inheritance.
Inserting a constructor in the ValidationDirective
also fixes the error.
🔬 Minimal Reproduction
https://github.com/CSchulz/angular-code-coverage-breaks-constructor-inheritance
Run npm test
results into
TypeError: Cannot read property ‘get’ of undefined
Run npm test -- --codeCoverage false
succeeds.
🔥 Exception or Error
For some reason the dependencies of the ValidationDirective
don’t get resolved correctly.
You can see in the createClass
method that the deps of ValidationDirective
are empty.
🌍 Your Environment
Angular CLI: 8.0.3
Node: 10.15.3
OS: darwin x64
Angular: 8.0.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.800.3
@angular-devkit/build-angular 0.800.3
@angular-devkit/build-ng-packagr 0.800.3
@angular-devkit/build-optimizer 0.800.3
@angular-devkit/build-webpack 0.800.3
@angular-devkit/core 8.0.3
@angular-devkit/schematics 8.0.3
@angular/cli 8.0.3
@ngtools/json-schema 1.1.0
@ngtools/webpack 8.0.3
@schematics/angular 8.0.3
@schematics/update 0.800.3
ng-packagr 5.3.0
rxjs 6.4.0
typescript 3.4.5
webpack 4.30.0
Issue Analytics
- State:
- Created 4 years ago
- Reactions:25
- Comments:16 (6 by maintainers)
Top Results From Across the Web
Code Coverage breaks constructor inheritance · Issue #44781
Running with code coverage enabled breaks constructor inheritance. Inserting a constructor in the ValidationDirective also fixes the error.
Read more >Angular 10 Dependency Injection fails for extension classes ...
The application runs as expected, with all dependencies correctly injected into the base class constructor on instantiation of the extension ...
Read more >Three Reasons Why We Should Not Use Inheritance In Our ...
1. Inheritance Is Not the Right Tool for Reusing Code · 2. Inheritance Can Have a Negative Effect to the Performance of Our...
Read more >Inheriting protected constructor and using declaration - Reddit
Constructors are nothing special. They're just another function that returns void and happens to always exist and be called at well known ...
Read more >Dependency injection in action - Angular
Take care when writing a component that inherits from another component. If the base component has injected dependencies, you must re-provide and re-inject...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I encountered this today with component, and I it somehow got fixed after overriding the constructor in the extending component.
For some reason, adding fields/functions to a component extending another component causes this error to appear. But overriding the constructor and calling super seems to fix it.
I’m aware that this is not a proper fix, but I prefer to keep our compiler target to es2015.
I also encountered the issue. When the flag
code-coverage
is set, then the dependencies are not injected in to the inherited constructor of the child class, in the unit tests. Which makes the tests to fail.It started to happen only when I changed the tsconfig’s target from
es5
toes2015
.Degrading the target back to
es5
is not a welcomed solution. After upgrading to Angular 13, which doesn’t support IE11, it makes sense to change the target in the unit tests toes2015
. Moreover, after upgrading to Angular 13, I had issues with some other tests when still using targetes5
. So I was kind of forced to update target toes2015
.@alan-agius4 do you think that in the times of Angular 13 we could increase a bit the severity of this issue? now it’s labelled
severity5: regression