Given the example spec test below
beforeEach(function () {
TestBed.configureTestingModule({
providers: [
{ provide: TranslateService, useClass: TranslateServiceMock },
{ provide: StoreService, useClass: StoreServiceMock },
{
provide: GLOBAL_CONFIG_TOKEN,
useValue: { default: true }
}
],
});
let config = TestBed.inject(GLOBAL_CONFIG_TOKEN);
});
it('should override provider otherwise what is the point? :)', () => {
let config = TestBed.overrideProvider(GLOBAL_CONFIG_TOKEN, { useValue: { default: false, random: 'damn' } });
expect(config).toEqual({default: false, random: 'damn'});
});
the thing is that test failed because default is always true and random is not a property of config. This means that config still has the default value during the configure of Testing Module and the provider hasn't been overridden.
Any idea why? Is overrideProvider method just a helper that updates the moduleRef object initially passed at configureTestingModule?