Skip to content

Commit

Permalink
fix(ivy): unable to override ComponentFactoryResolver provider in tes…
Browse files Browse the repository at this point in the history
…ts (#32512)

PR Close #32512
  • Loading branch information
atscott authored and matsko committed Sep 10, 2019
1 parent 7280710 commit 2124588
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/core/src/di/r3_injector.ts
Expand Up @@ -116,15 +116,16 @@ export class R3Injector {
constructor(
def: InjectorType<any>, additionalProviders: StaticProvider[]|null, readonly parent: Injector,
source: string|null = null) {
// Start off by creating Records for every provider declared in every InjectorType
// included transitively in `def`.
const dedupStack: InjectorType<any>[] = [];
deepForEach([def], injectorDef => this.processInjectorType(injectorDef, [], dedupStack));

// Start off by creating Records for every provider declared in every InjectorType
// included transitively in additional providers then do the same for `def`. This order is
// important because `def` may include providers that override ones in additionalProviders.
additionalProviders && deepForEach(
additionalProviders, provider => this.processProvider(
provider, def, additionalProviders));

deepForEach([def], injectorDef => this.processInjectorType(injectorDef, [], dedupStack));

// Make sure the INJECTOR token provides this injector.
this.records.set(INJECTOR, makeRecord(undefined, this));
Expand Down
12 changes: 11 additions & 1 deletion packages/platform-browser/test/testing_public_spec.ts
Expand Up @@ -7,7 +7,7 @@
*/

import {CompilerConfig, ResourceLoader} from '@angular/compiler';
import {CUSTOM_ELEMENTS_SCHEMA, Compiler, Component, Directive, Inject, Injectable, InjectionToken, Injector, Input, NgModule, Optional, Pipe, SkipSelf, ɵstringify as stringify} from '@angular/core';
import {CUSTOM_ELEMENTS_SCHEMA, Compiler, Component, ComponentFactoryResolver, Directive, Inject, Injectable, InjectionToken, Injector, Input, NgModule, Optional, Pipe, SkipSelf, ɵstringify as stringify} from '@angular/core';
import {TestBed, async, fakeAsync, getTestBed, inject, tick, withModule} from '@angular/core/testing';
import {expect} from '@angular/platform-browser/testing/src/matchers';
import {ivyEnabled, modifiedInIvy, obsoleteInIvy, onlyInIvy} from '@angular/private/testing';
Expand Down Expand Up @@ -418,6 +418,16 @@ const bTok = new InjectionToken<string>('b');
});

describe('overriding providers', () => {

describe('in core', () => {
it('ComponentFactoryResolver', () => {
const componentFactoryMock =
jasmine.createSpyObj('componentFactory', ['resolveComponentFactory']);
TestBed.overrideProvider(ComponentFactoryResolver, {useValue: componentFactoryMock});
expect(TestBed.get(ComponentFactoryResolver)).toEqual(componentFactoryMock);
});
});

describe('in NgModules', () => {

it('should support useValue', () => {
Expand Down

0 comments on commit 2124588

Please sign in to comment.