I want to test an Angular module, in my spec, I create the module using TestBed.configureTestingModule
.
in my testing needs, I want to create multiple modules
or accurately, create the module in multiple ways, for example using .forRoot()
, .forChild()
, or without, or by providing different values for providers
describe("init", ()=>{
test("using .forRoot()", ()=>{
TestBed.configureTestingModule({
imports: [MyModule.forRoot(config)],
});
expect(TestBed.inject(MyService)).toBeInstanceOf(MyService1);
})
test("using .forChild()", ()=>{
TestBed.configureTestingModule({
imports: [MyModule.forChild(config)],
});
expect(TestBed.inject(MyService)).toBeInstanceOf(MyService2);
})
})
this configuration gives me an error due to configuring the testing module multiple times
Cannot configure the test module when the test module has already been instantiated. Make sure you are not using `inject` before `R3TestBed.configureTestingModule`.