-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Description
🚀 feature request
Relevant Package
This feature request is for @angular/core
Description
Typings for TestModuleMetadata are too loose and they do not provide proper type-checking. Ths can lead to hard-to-track bugs in tests in case there is a typo or some other error in TestBed configuration object.
Example issue:
TestBed.configureTestingModule({
providers: [{
provibe: SomeService,
useClass: SomeServiceMock,
}],
})If SomeService is decorated as @Injectable({ providedIn: 'root' }), the test for the above TestBed configuration will actually create an instance of SomeService instead of SomeServiceMock because there is a typo (provibe instead of provide) in the provider so this provider is basically ignored. This kind of an error can be hard to pin down and could be easily caught by stricter typings for TestModuleMetadata.
Describe the solution you'd like
I suggest updating typings of TestModuleMetadata to match the typings of NgModule interface. Please check the related PR I created.
Describe alternatives you've considered
Alternative solution is to explicitly type the providers yourself:
const testProviders: Array<Provider> = [{
provibe: SomeService, // now this typo will be caught
useClass: SomeServiceMock,
}];
TestBed.configureTestingModule({
providers: testProviders,
})