I'm working on unit tests within my Angular app , i'm using TestBed approach ,
I'm testing components , so each spec file looks like this
import...
describe('AppComponent', () => {
// Importing dependecies
beforeEach(async(() => {
TestBed.configureTestingModule({
imports : [RouterTestingModule , HttpModule , FormsModule ],
declarations: [AppComponent
],
providers: [AUTH_PROVIDERS ,UserService, SharedclientService, RouteNavigator, JwtHelper, ReloadTokenService, ShopService
, EnvVarsService, ProfileService, LocalStorageService, ApiVersionInterceptor, ApiTrackingInterceptor, MonitoringService ,
{ provide: 'LOCAL_STORAGE_SERVICE_CONFIG', useValue: userConfig } , TokenUtilService , HttpInterceptorService ,
{ provide: InterceptableStoreFactory, useClass: InterceptableStoreFactoryMock },ReloadTokenEventService , InterceptableStoreFactory
]
}).compileComponents();
}));
// detecting changes every times
beforeEach(() => {
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
// Test case 0 (compilation of the component)
it('AppComponent is well defined', () => {
expect(component).toBeDefined();
});
// Test case 1
it('test', () => {
expect("1").toBe("1");
});
});
This approach of testing , is causing the failure of the whole test suite , if the dependencies importing isn't well.
For example : in this test suite , it throws this error :
No provider for InterceptableStoreFactory! It seems to be strange , as i'm importing this service in my providers (last one)
This causes almost the failure of all test cases assince the verification of the fixture imports is "beforeEach" test cases
Am looking for better ideas for :
- the problem of "no provider for service" (which is already added to providers"
and for
- unit testBed better way of testing