From 7561698675980966898c0c042fec43763d97a4b2 Mon Sep 17 00:00:00 2001 From: Kara Erickson Date: Thu, 14 Mar 2019 18:31:27 -0700 Subject: [PATCH] fix(ivy): add temporary hack for deprecatedOverrideProvider (#29324) HACK: This is NOT the correct implementation for deprecatedOverrideProvider. We do not plan to implement this at all since the API is deprecated and scheduled for removal in V8. This hack is here temporarily for Ivy testing until we transition apps inside Google to the overrideProvider API. At that point, we will be able to remove this method entirely. In the meantime, we can use overrideProvider here to test apps with Ivy that don't care about eager instantiation. This fixes 97% of cases in our blueprint. PR Close #29324 --- packages/core/testing/src/r3_test_bed.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/core/testing/src/r3_test_bed.ts b/packages/core/testing/src/r3_test_bed.ts index 49f8989ea4..1270ce51ff 100644 --- a/packages/core/testing/src/r3_test_bed.ts +++ b/packages/core/testing/src/r3_test_bed.ts @@ -210,7 +210,8 @@ export class TestBedRender3 implements Injector, TestBed { useValue?: any, deps?: any[], }): TestBedStatic { - throw new Error('Render3TestBed.deprecatedOverrideProvider is not implemented'); + _getTestBedRender3().deprecatedOverrideProvider(token, provider as any); + return TestBedRender3 as any as TestBedStatic; } static get(token: any, notFoundValue: any = Injector.THROW_IF_NOT_FOUND): any { @@ -495,7 +496,16 @@ export class TestBedRender3 implements Injector, TestBed { deprecatedOverrideProvider(token: any, provider: {useValue: any;}): void; deprecatedOverrideProvider( token: any, provider: {useFactory?: Function, useValue?: any, deps?: any[]}): void { - throw new Error('No implemented in IVY'); + // HACK: This is NOT the correct implementation for deprecatedOverrideProvider. + // To implement it in a backward compatible way, we would need to record some state + // so we know to prevent eager instantiation of NgModules. However, we don't plan + // to implement this at all since the API is deprecated and scheduled for removal + // in V8. This hack is here temporarily for Ivy testing until we transition apps + // inside Google to the overrideProvider API. At that point, we will be able to + // remove this method entirely. In the meantime, we can use overrideProvider to + // test apps with Ivy that don't care about eager instantiation. This fixes 85% + // of cases in our blueprint. + this.overrideProvider(token, provider as any); } createComponent(type: Type): ComponentFixture {