In one of my unit test files, I have to mock several times the same service with different mocks.
import { MyService } from \'../services/myservice.service\'
Just for reference, if annynone meets this issue.
I tried to use
TestBed.overrideProvider(MockedService, {useValue: { foo: () => {} } });
it was not working, still the original service was injected in test (that with providedIn: root
)
In test I used alias to import OtherService
:
import { OtherService } from '@core/OtherService'`
while in the service itself I had import with relative path:
import { OtherService } from '../../../OtherService'
After correcting it so both test and service itself had same imports TestBed.overrideProvider()
started to take effect.
Env: Angular 7 library - not application and jest