-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Description
🐞 bug report
Affected Package
The issue is caused by package @angular/core@^8
Is this a regression?
Yes, the previous version in which this bug was not present was: @angular/core@7
Description
The problem occurs when:
- The base class has a constructor with an injected service. (
Injectorfrom the example)
@Injectable()
export class BaseService {
// "Injector" is just for the sake of example. Any injectable would have the same problem.
constructor(public injector: Injector) {
}
}- Child class has no constructor (i.e., it relies on base class constructor) AND at least one property with the default value.
@Injectable()
export class MyLibService extends BaseService {
public foo = 'bar';
}- (dont ask me how I have found this, but:) In
angular.json[lib name].test.options.codeCoverageshould be true.
PROBLEM:
injector is undefined in the instance of MyLibService.
🚩 Removing property from the child class (2) AND/OR opting out codeCoverage config in angular.json (3) doesn't brake test.
As a result, I can't have a class inheritance and code coverage at the same time.
I could put a constructor in the child class and call super by passing all required arguments manually, but it's the last option since the real-life scenario is much more complicated than the example provided here.
🔬 Minimal Reproduction
git repo: https://github.com/ddramone/ng-8-library-inheritance-di-test-bug
reproduce steps:
- Install angular 8 cli
- Clone
git clone https://github.com/ddramone/ng-8-library-inheritance-di-test-bug.git npm i- run Test
ng test my-lib
Expected behavior
Test should pass = Injector service should be available in the service instance.