Maybe it's side effect of this new functionality, but if I have a service as
@Injectable({
providedIn: 'root'
})
export class MyService {...}
and I have MyComponent
which uses this. Now, when I make a test for that component, I simply do and it works!
TestBed.configureTestingModule({
declarations: [ MyComponent ]
})
.compileComponents();
That means that my service implicitly provided. I think it's very dangerous behaviour for testing. Is it possible to prevent this auto-providing?
Use Testbed.overrideProvider in your case it will be
TestBed.overrideProvider(MyService, { useValue: MyServiceMock });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With