Skip to content

Commit

Permalink
fix(common): Fix TestBed.overrideProvider type to include multi (#48424)
Browse files Browse the repository at this point in the history
TestBed.overrideProvider should include `multi` support in its type. The
underlying implementation already supports it, as documented by the
tests which are currently casting the override to `any` to get around
the bad type.

PR Close #48424
  • Loading branch information
atscott authored and thePunderWoman committed Dec 12, 2022
1 parent ffb2c9c commit f30d18a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
3 changes: 3 additions & 0 deletions goldens/public-api/core/testing/index.md
Expand Up @@ -140,16 +140,19 @@ export interface TestBed {
overrideProvider(token: any, provider: {
useFactory: Function;
deps: any[];
multi?: boolean;
}): TestBed;
// (undocumented)
overrideProvider(token: any, provider: {
useValue: any;
multi?: boolean;
}): TestBed;
// (undocumented)
overrideProvider(token: any, provider: {
useFactory?: Function;
useValue?: any;
deps?: any[];
multi?: boolean;
}): TestBed;
// (undocumented)
overrideTemplate(component: Type<any>, template: string): TestBed;
Expand Down
6 changes: 3 additions & 3 deletions packages/core/test/test_bed_spec.ts
Expand Up @@ -1020,7 +1020,7 @@ describe('TestBed', () => {

it('overridden with an array', () => {
const overrideValue = ['override'];
TestBed.overrideProvider(multiToken, {useValue: overrideValue, multi: true} as any);
TestBed.overrideProvider(multiToken, {useValue: overrideValue, multi: true});

const value = TestBed.inject(multiToken);
expect(value.length).toEqual(overrideValue.length);
Expand All @@ -1031,7 +1031,7 @@ describe('TestBed', () => {
// This is actually invalid because multi providers return arrays. We have this here so we can
// ensure Ivy behaves the same as VE does currently.
const overrideValue = 'override';
TestBed.overrideProvider(multiToken, {useValue: overrideValue, multi: true} as any);
TestBed.overrideProvider(multiToken, {useValue: overrideValue, multi: true});

const value = TestBed.inject(multiToken);
expect(value.length).toEqual(overrideValue.length);
Expand Down Expand Up @@ -1248,7 +1248,7 @@ describe('TestBed', () => {
});

const multiOverride = {useValue: [{value: 'new provider'}], multi: true};
TestBed.overrideProvider(MY_TOKEN, multiOverride as any);
TestBed.overrideProvider(MY_TOKEN, multiOverride);

const fixture = TestBed.createComponent(MyComp);
expect(fixture.componentInstance.myProviders).toEqual([{value: 'new provider'}]);
Expand Down
11 changes: 5 additions & 6 deletions packages/core/testing/src/test_bed.ts
Expand Up @@ -119,13 +119,12 @@ export interface TestBed {
/**
* Overwrites all providers for the given token with the given provider definition.
*/
overrideProvider(token: any, provider: {
useFactory: Function,
deps: any[],
}): TestBed;
overrideProvider(token: any, provider: {useValue: any;}): TestBed;
overrideProvider(token: any, provider: {useFactory?: Function, useValue?: any, deps?: any[]}):
overrideProvider(token: any, provider: {useFactory: Function, deps: any[], multi?: boolean}):
TestBed;
overrideProvider(token: any, provider: {useValue: any, multi?: boolean}): TestBed;
overrideProvider(
token: any,
provider: {useFactory?: Function, useValue?: any, deps?: any[], multi?: boolean}): TestBed;

overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBed;

Expand Down

0 comments on commit f30d18a

Please sign in to comment.