fix(core): don't override ngInjectableDef in the decorator if present on the type (#22943)
Previously, @Injectable() would generate an ngInjectableDef on the type it was decorating, even if that type already had a compiled ngInjectableDef, overwriting the compiled version. PR Close #22943
This commit is contained in:

committed by
Matias Niemelä

parent
4f0cae0676
commit
6f0191744c
@ -124,4 +124,22 @@ describe('ngInjectableDef Bazel Integration', () => {
|
||||
|
||||
expect(TestBed.get(Service).value).toEqual('overridden');
|
||||
});
|
||||
|
||||
it('does not override existing ngInjectableDef', () => {
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
useValue: new Service(false),
|
||||
})
|
||||
class Service {
|
||||
constructor(public value: boolean) {}
|
||||
static ngInjectableDef = {
|
||||
providedIn: 'root',
|
||||
factory: () => new Service(true),
|
||||
token: Service,
|
||||
};
|
||||
}
|
||||
|
||||
TestBed.configureTestingModule({});
|
||||
expect(TestBed.get(Service).value).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user