Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(common): Fix TestBed.overrideProvider type to include multi #48424

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -127,13 +127,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