From 5a4e46db20beaf0e13ad19d9a8344a9d56c8d04c Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 9 Sep 2016 12:04:38 -0700 Subject: [PATCH] refactor(tests): simplify code (#11485) --- .../common/test/pipes/json_pipe_spec.ts | 6 +- .../common/test/pipes/slice_pipe_spec.ts | 6 +- .../animation/animation_integration_spec.ts | 116 ++++----- .../core/test/debug/debug_node_spec.ts | 8 +- .../core/test/linker/integration_spec.ts | 138 +++++----- .../linker/ng_container_integration_spec.ts | 14 +- .../linker/projection_integration_spec.ts | 94 +++---- .../test/linker/query_integration_spec.ts | 26 +- .../linker/regression_integration_spec.ts | 3 +- .../test/linker/security_integration_spec.ts | 15 +- .../core/testing/component_fixture.ts | 16 +- .../@angular/forms/test/form_array_spec.ts | 2 +- .../@angular/forms/test/form_builder_spec.ts | 2 +- .../forms/test/reactive_integration_spec.ts | 246 +++++++++--------- .../forms/test/template_integration_spec.ts | 151 ++++++----- .../@angular/forms/test/validators_spec.ts | 4 +- .../test/testing_public_browser_spec.ts | 3 +- .../test/testing_public_spec.ts | 18 +- .../worker/renderer_integration_spec.ts | 16 +- .../@angular/router/test/integration.spec.ts | 163 ++++++------ .../public_api_guard/core/testing/index.d.ts | 2 +- 21 files changed, 505 insertions(+), 544 deletions(-) diff --git a/modules/@angular/common/test/pipes/json_pipe_spec.ts b/modules/@angular/common/test/pipes/json_pipe_spec.ts index edb6fa9ca0..84fe860378 100644 --- a/modules/@angular/common/test/pipes/json_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/json_pipe_spec.ts @@ -67,13 +67,13 @@ export function main() { it('should work with mutable objects', async(() => { let fixture = TestBed.createComponent(TestComp); let mutable: number[] = [1]; - fixture.debugElement.componentInstance.data = mutable; + fixture.componentInstance.data = mutable; fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('[\n 1\n]'); + expect(fixture.nativeElement).toHaveText('[\n 1\n]'); mutable.push(2); fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('[\n 1,\n 2\n]'); + expect(fixture.nativeElement).toHaveText('[\n 1,\n 2\n]'); })); }); diff --git a/modules/@angular/common/test/pipes/slice_pipe_spec.ts b/modules/@angular/common/test/pipes/slice_pipe_spec.ts index c9eb5c751c..683f9bb5a6 100644 --- a/modules/@angular/common/test/pipes/slice_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/slice_pipe_spec.ts @@ -96,13 +96,13 @@ export function main() { it('should work with mutable arrays', async(() => { let fixture = TestBed.createComponent(TestComp); let mutable: number[] = [1, 2]; - fixture.debugElement.componentInstance.data = mutable; + fixture.componentInstance.data = mutable; fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('2'); + expect(fixture.nativeElement).toHaveText('2'); mutable.push(3); fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('2,3'); + expect(fixture.nativeElement).toHaveText('2,3'); })); }); }); diff --git a/modules/@angular/core/test/animation/animation_integration_spec.ts b/modules/@angular/core/test/animation/animation_integration_spec.ts index 1d8ab43f5e..88a1f56cbe 100644 --- a/modules/@angular/core/test/animation/animation_integration_spec.ts +++ b/modules/@angular/core/test/animation/animation_integration_spec.ts @@ -59,7 +59,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = true; fixture.detectChanges(); flushMicrotasks(); @@ -88,7 +88,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = true; fixture.detectChanges(); @@ -125,7 +125,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = 'state1'; fixture.detectChanges(); @@ -164,7 +164,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = true; fixture.detectChanges(); flushMicrotasks(); @@ -209,7 +209,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = true; fixture.detectChanges(); @@ -278,7 +278,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = true; fixture.detectChanges(); @@ -334,7 +334,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = true; fixture.detectChanges(); @@ -395,7 +395,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; const fixture = TestBed.createComponent(DummyIfCmp); - const cmp = fixture.debugElement.componentInstance; + const cmp = fixture.componentInstance; cmp.exp = true; fixture.detectChanges(); @@ -427,7 +427,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = true; fixture.detectChanges(); flushMicrotasks(); @@ -466,7 +466,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = true; fixture.detectChanges(); flushMicrotasks(); @@ -498,7 +498,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = 'state1'; fixture.detectChanges(); @@ -544,7 +544,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = true; fixture.detectChanges(); @@ -592,7 +592,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = 'start'; cmp.exp2 = 'start'; @@ -639,7 +639,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = true; fixture.detectChanges(); flushMicrotasks(); @@ -649,7 +649,7 @@ function declareTests({useJit}: {useJit: boolean}) { flushMicrotasks(); var player = driver.log[0]['player']; - var container = fixture.debugElement.nativeElement; + var container = fixture.nativeElement; var ifElm = getDOM().querySelector(container, '.my-if'); expect(ifElm).toBeTruthy(); @@ -677,7 +677,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = 'state1'; fixture.detectChanges(); flushMicrotasks(); @@ -716,7 +716,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = 'state1'; cmp.exp2 = 'state1'; fixture.detectChanges(); @@ -784,8 +784,8 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; - var parent = fixture.debugElement.nativeElement; + var cmp = fixture.componentInstance; + var parent = fixture.nativeElement; cmp.items = [0, 2, 4, 6, 8]; fixture.detectChanges(); flushMicrotasks(); @@ -813,8 +813,8 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; - var parent = fixture.debugElement.nativeElement; + var cmp = fixture.componentInstance; + var parent = fixture.nativeElement; cmp.items = [0, 1, 2, 3, 4]; fixture.detectChanges(); @@ -879,8 +879,8 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as InnerContentTrackingAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; - var node = getDOM().querySelector(fixture.debugElement.nativeElement, '.target'); + var cmp = fixture.componentInstance; + var node = getDOM().querySelector(fixture.nativeElement, '.target'); cmp.exp = true; cmp.exp2 = true; fixture.detectChanges(); @@ -911,7 +911,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as InnerContentTrackingAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = true; cmp.exp2 = true; fixture.detectChanges(); @@ -943,7 +943,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as InnerContentTrackingAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = true; cmp.exp2 = true; fixture.detectChanges(); @@ -972,7 +972,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as InnerContentTrackingAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = true; fixture.detectChanges(); flushMicrotasks(); @@ -1010,7 +1010,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as InnerContentTrackingAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = true; cmp.exp2 = true; fixture.detectChanges(); @@ -1051,7 +1051,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as InnerContentTrackingAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = true; cmp.exp2 = true; fixture.detectChanges(); @@ -1087,7 +1087,7 @@ function declareTests({useJit}: {useJit: boolean}) { let fixture = TestBed.createComponent(DummyIfCmp); var isAnimationRunning = false; var calls = 0; - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.callback = (e: AnimationTransitionEvent) => { isAnimationRunning = e.totalTime > 0; calls++; @@ -1123,7 +1123,7 @@ function declareTests({useJit}: {useJit: boolean}) { let fixture = TestBed.createComponent(DummyIfCmp); var isAnimationRunning = false; var calls = 0; - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.callback = (e: AnimationTransitionEvent) => { isAnimationRunning = e.totalTime > 0; calls++; @@ -1165,7 +1165,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as InnerContentTrackingAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); var eventData: AnimationTransitionEvent = null; - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.callback = (e: AnimationTransitionEvent) => { eventData = e; }; cmp.exp = 'one'; fixture.detectChanges(); @@ -1202,7 +1202,7 @@ function declareTests({useJit}: {useJit: boolean}) { let fixture = TestBed.createComponent(DummyIfCmp); var eventData1: AnimationTransitionEvent = null; var eventData2: AnimationTransitionEvent = null; - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.callback1 = (e: AnimationTransitionEvent) => { eventData1 = e; }; cmp.callback2 = (e: AnimationTransitionEvent) => { eventData2 = e; }; cmp.exp = 'one'; @@ -1347,7 +1347,7 @@ function declareTests({useJit}: {useJit: boolean}) { var ifCalls = 0; var loadingCalls = 0; let fixture = TestBed.createComponent(DummyIfCmp); - var ifCmp = fixture.debugElement.componentInstance; + var ifCmp = fixture.componentInstance; var loadingCmp = fixture.debugElement.childNodes[1].componentInstance; ifCmp.callback = (e: any) => ifCalls++; @@ -1390,7 +1390,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as InnerContentTrackingAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; var startCalls = [0, 0, 0, 0, 0]; var doneCalls = [0, 0, 0, 0, 0]; @@ -1442,7 +1442,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as InnerContentTrackingAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = true; cmp.exp2 = 'blue'; fixture.detectChanges(); @@ -1500,7 +1500,7 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyLoadingCmp); - var cmp = fixture.debugElement.componentInstance; + var cmp = fixture.componentInstance; cmp.exp = 'final'; fixture.detectChanges(); flushMicrotasks(); @@ -1542,8 +1542,8 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; - var node = getDOM().querySelector(fixture.debugElement.nativeElement, '.target'); + var cmp = fixture.componentInstance; + var node = getDOM().querySelector(fixture.nativeElement, '.target'); cmp.exp = 'final'; fixture.detectChanges(); flushMicrotasks(); @@ -1575,8 +1575,8 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; - var node = getDOM().querySelector(fixture.debugElement.nativeElement, '.target'); + var cmp = fixture.componentInstance; + var node = getDOM().querySelector(fixture.nativeElement, '.target'); cmp.exp = 'green'; fixture.detectChanges(); flushMicrotasks(); @@ -1631,8 +1631,8 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; - var node = getDOM().querySelector(fixture.debugElement.nativeElement, '.target'); + var cmp = fixture.componentInstance; + var node = getDOM().querySelector(fixture.nativeElement, '.target'); cmp.exp = 'final'; fixture.detectChanges(); flushMicrotasks(); @@ -1659,8 +1659,8 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; - var node = getDOM().querySelector(fixture.debugElement.nativeElement, '.target'); + var cmp = fixture.componentInstance; + var node = getDOM().querySelector(fixture.nativeElement, '.target'); cmp.exp = 'final'; fixture.detectChanges(); flushMicrotasks(); @@ -1688,8 +1688,8 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; - var node = getDOM().querySelector(fixture.debugElement.nativeElement, '.target'); + var cmp = fixture.componentInstance; + var node = getDOM().querySelector(fixture.nativeElement, '.target'); cmp.exp = 'a'; fixture.detectChanges(); @@ -1744,8 +1744,8 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; - var node = getDOM().querySelector(fixture.debugElement.nativeElement, '.target'); + var cmp = fixture.componentInstance; + var node = getDOM().querySelector(fixture.nativeElement, '.target'); cmp.exp = 'a'; fixture.detectChanges(); @@ -1791,8 +1791,8 @@ function declareTests({useJit}: {useJit: boolean}) { const driver = TestBed.get(AnimationDriver) as MockAnimationDriver; let fixture = TestBed.createComponent(DummyIfCmp); - var cmp = fixture.debugElement.componentInstance; - var node = getDOM().querySelector(fixture.debugElement.nativeElement, '.target'); + var cmp = fixture.componentInstance; + getDOM().querySelector(fixture.nativeElement, '.target'); cmp.exp = 'final'; fixture.detectChanges(); @@ -1843,27 +1843,25 @@ class InnerContentTrackingAnimationPlayer extends MockAnimationPlayer { @Component({ selector: 'if-cmp', animations: [trigger('myAnimation', [])], - template: ` -
- ` + template: `
` }) class DummyIfCmp { - exp = false; - exp2 = false; + exp: any = false; + exp2: any = false; items = [0, 1, 2, 3, 4]; callback: Function = () => {}; + callback1: Function = () => {}; + callback2: Function = () => {}; } @Component({ selector: 'dummy-loading-cmp', host: {'[@loading]': 'exp'}, animations: [trigger('loading', [])], - template: ` -
loading...
- ` + template: `
loading...
` }) class DummyLoadingCmp { - exp = false; + exp: any = false; callback = () => {}; } diff --git a/modules/@angular/core/test/debug/debug_node_spec.ts b/modules/@angular/core/test/debug/debug_node_spec.ts index 04fb637fbb..a4fed0f2be 100644 --- a/modules/@angular/core/test/debug/debug_node_spec.ts +++ b/modules/@angular/core/test/debug/debug_node_spec.ts @@ -345,14 +345,14 @@ export function main() { fixture = TestBed.createComponent(EventsComp); fixture.detectChanges(); - expect(fixture.debugElement.componentInstance.clicked).toBe(false); - expect(fixture.debugElement.componentInstance.customed).toBe(false); + expect(fixture.componentInstance.clicked).toBe(false); + expect(fixture.componentInstance.customed).toBe(false); fixture.debugElement.children[0].triggerEventHandler('click', {}); - expect(fixture.debugElement.componentInstance.clicked).toBe(true); + expect(fixture.componentInstance.clicked).toBe(true); fixture.debugElement.children[1].triggerEventHandler('myevent', {}); - expect(fixture.debugElement.componentInstance.customed).toBe(true); + expect(fixture.componentInstance.customed).toBe(true); }); }); diff --git a/modules/@angular/core/test/linker/integration_spec.ts b/modules/@angular/core/test/linker/integration_spec.ts index a0e795f2ef..d1975a114e 100644 --- a/modules/@angular/core/test/linker/integration_spec.ts +++ b/modules/@angular/core/test/linker/integration_spec.ts @@ -44,10 +44,10 @@ function declareTests({useJit}: {useJit: boolean}) { const template = '
{{ctxProp}}
'; TestBed.overrideComponent(MyComp, {set: {template}}); const fixture = TestBed.createComponent(MyComp); - fixture.debugElement.componentInstance.ctxProp = 'Hello World!'; + fixture.componentInstance.ctxProp = 'Hello World!'; fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('Hello World!'); + expect(fixture.nativeElement).toHaveText('Hello World!'); }); it('should update text node with a blank string when interpolation evaluates to null', () => { @@ -55,10 +55,10 @@ function declareTests({useJit}: {useJit: boolean}) { const template = '
{{null}}{{ctxProp}}
'; TestBed.overrideComponent(MyComp, {set: {template}}); const fixture = TestBed.createComponent(MyComp); - fixture.debugElement.componentInstance.ctxProp = null; + fixture.componentInstance.ctxProp = null; fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText(''); + expect(fixture.nativeElement).toHaveText(''); }); it('should consume element binding changes', () => { @@ -67,7 +67,7 @@ function declareTests({useJit}: {useJit: boolean}) { TestBed.overrideComponent(MyComp, {set: {template}}); const fixture = TestBed.createComponent(MyComp); - fixture.debugElement.componentInstance.ctxProp = 'Hello World!'; + fixture.componentInstance.ctxProp = 'Hello World!'; fixture.detectChanges(); expect(fixture.debugElement.children[0].nativeElement.id).toEqual('Hello World!'); @@ -79,12 +79,12 @@ function declareTests({useJit}: {useJit: boolean}) { TestBed.overrideComponent(MyComp, {set: {template}}); const fixture = TestBed.createComponent(MyComp); - fixture.debugElement.componentInstance.ctxProp = 'Initial aria label'; + fixture.componentInstance.ctxProp = 'Initial aria label'; fixture.detectChanges(); expect(getDOM().getAttribute(fixture.debugElement.children[0].nativeElement, 'aria-label')) .toEqual('Initial aria label'); - fixture.debugElement.componentInstance.ctxProp = 'Changed aria label'; + fixture.componentInstance.ctxProp = 'Changed aria label'; fixture.detectChanges(); expect(getDOM().getAttribute(fixture.debugElement.children[0].nativeElement, 'aria-label')) .toEqual('Changed aria label'); @@ -96,12 +96,12 @@ function declareTests({useJit}: {useJit: boolean}) { TestBed.overrideComponent(MyComp, {set: {template}}); const fixture = TestBed.createComponent(MyComp); - fixture.debugElement.componentInstance.ctxProp = 'bar'; + fixture.componentInstance.ctxProp = 'bar'; fixture.detectChanges(); expect(getDOM().getAttribute(fixture.debugElement.children[0].nativeElement, 'foo')) .toEqual('bar'); - fixture.debugElement.componentInstance.ctxProp = null; + fixture.componentInstance.ctxProp = null; fixture.detectChanges(); expect(getDOM().hasAttribute(fixture.debugElement.children[0].nativeElement, 'foo')) .toBeFalsy(); @@ -113,12 +113,12 @@ function declareTests({useJit}: {useJit: boolean}) { TestBed.overrideComponent(MyComp, {set: {template}}); const fixture = TestBed.createComponent(MyComp); - fixture.debugElement.componentInstance.ctxProp = '10'; + fixture.componentInstance.ctxProp = '10'; fixture.detectChanges(); expect(getDOM().getStyle(fixture.debugElement.children[0].nativeElement, 'height')) .toEqual('10px'); - fixture.debugElement.componentInstance.ctxProp = null; + fixture.componentInstance.ctxProp = null; fixture.detectChanges(); expect(getDOM().getStyle(fixture.debugElement.children[0].nativeElement, 'height')) .toEqual(''); @@ -134,7 +134,7 @@ function declareTests({useJit}: {useJit: boolean}) { fixture.detectChanges(); expect(fixture.debugElement.children[0].nativeElement.tabIndex).toEqual(0); - fixture.debugElement.componentInstance.ctxNumProp = 5; + fixture.componentInstance.ctxNumProp = 5; fixture.detectChanges(); expect(fixture.debugElement.children[0].nativeElement.tabIndex).toEqual(5); }); @@ -148,7 +148,7 @@ function declareTests({useJit}: {useJit: boolean}) { fixture.detectChanges(); expect(fixture.debugElement.children[0].nativeElement.readOnly).toBeFalsy(); - fixture.debugElement.componentInstance.ctxBoolProp = true; + fixture.componentInstance.ctxBoolProp = true; fixture.detectChanges(); expect(fixture.debugElement.children[0].nativeElement.readOnly).toBeTruthy(); }); @@ -159,12 +159,12 @@ function declareTests({useJit}: {useJit: boolean}) { TestBed.overrideComponent(MyComp, {set: {template}}); const fixture = TestBed.createComponent(MyComp); - fixture.debugElement.componentInstance.ctxProp = 'Some HTML'; + fixture.componentInstance.ctxProp = 'Some HTML'; fixture.detectChanges(); expect(getDOM().getInnerHTML(fixture.debugElement.children[0].nativeElement)) .toEqual('Some HTML'); - fixture.debugElement.componentInstance.ctxProp = 'Some other
HTML
'; + fixture.componentInstance.ctxProp = 'Some other
HTML
'; fixture.detectChanges(); expect(getDOM().getInnerHTML(fixture.debugElement.children[0].nativeElement)) .toEqual('Some other
HTML
'); @@ -177,7 +177,7 @@ function declareTests({useJit}: {useJit: boolean}) { const fixture = TestBed.createComponent(MyComp); var nativeEl = fixture.debugElement.children[0].nativeElement; - fixture.debugElement.componentInstance.ctxProp = 'foo bar'; + fixture.componentInstance.ctxProp = 'foo bar'; fixture.detectChanges(); expect(nativeEl).toHaveCssClass('foo'); @@ -196,7 +196,7 @@ function declareTests({useJit}: {useJit: boolean}) { TestBed.overrideComponent(MyComp, {set: {template}}); const fixture = TestBed.createComponent(MyComp); - fixture.debugElement.componentInstance.ctxProp = 'Hello World!'; + fixture.componentInstance.ctxProp = 'Hello World!'; fixture.detectChanges(); var containerSpan = fixture.debugElement.children[0]; @@ -215,7 +215,7 @@ function declareTests({useJit}: {useJit: boolean}) { TestBed.overrideComponent(MyComp, {set: {template}}); const fixture = TestBed.createComponent(MyComp); - fixture.debugElement.componentInstance.ctxProp = 'a'; + fixture.componentInstance.ctxProp = 'a'; fixture.detectChanges(); var dir = fixture.debugElement.children[0].references['dir']; @@ -231,7 +231,7 @@ function declareTests({useJit}: {useJit: boolean}) { fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('hello'); + expect(fixture.nativeElement).toHaveText('hello'); }); // GH issue 328 - https://github.com/angular/angular/issues/328 @@ -241,7 +241,7 @@ function declareTests({useJit}: {useJit: boolean}) { TestBed.overrideComponent(MyComp, {set: {template}}); const fixture = TestBed.createComponent(MyComp); - fixture.debugElement.componentInstance.ctxProp = 'Hello World!'; + fixture.componentInstance.ctxProp = 'Hello World!'; fixture.detectChanges(); var tc = fixture.debugElement.children[0]; @@ -263,7 +263,7 @@ function declareTests({useJit}: {useJit: boolean}) { const template = '

'; TestBed.overrideComponent(MyComp, {set: {template}}); const fixture = TestBed.createComponent(MyComp); - expect(fixture.debugElement.nativeElement).toHaveText('noduplicate'); + expect(fixture.nativeElement).toHaveText('noduplicate'); }); it('should support directives where a selector matches property binding', () => { @@ -275,11 +275,11 @@ function declareTests({useJit}: {useJit: boolean}) { var tc = fixture.debugElement.children[0]; var idDir = tc.injector.get(IdDir); - fixture.debugElement.componentInstance.ctxProp = 'some_id'; + fixture.componentInstance.ctxProp = 'some_id'; fixture.detectChanges(); expect(idDir.id).toEqual('some_id'); - fixture.debugElement.componentInstance.ctxProp = 'other_id'; + fixture.componentInstance.ctxProp = 'other_id'; fixture.detectChanges(); expect(idDir.id).toEqual('other_id'); }); @@ -310,7 +310,7 @@ function declareTests({useJit}: {useJit: boolean}) { fixture.detectChanges(); - var childNodesOfWrapper = getDOM().childNodes(fixture.debugElement.nativeElement); + var childNodesOfWrapper = getDOM().childNodes(fixture.nativeElement); // 1 template + 2 copies. expect(childNodesOfWrapper.length).toBe(3); expect(childNodesOfWrapper[1]).toHaveText('hello'); @@ -325,7 +325,7 @@ function declareTests({useJit}: {useJit: boolean}) { const fixture = TestBed.createComponent(MyComp); fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('baz'); + expect(fixture.nativeElement).toHaveText('baz'); }); it('should not detach views in ViewContainers when the parent view is destroyed.', () => { @@ -335,7 +335,7 @@ function declareTests({useJit}: {useJit: boolean}) { TestBed.overrideComponent(MyComp, {set: {template}}); const fixture = TestBed.createComponent(MyComp); - fixture.debugElement.componentInstance.ctxBoolProp = true; + fixture.componentInstance.ctxBoolProp = true; fixture.detectChanges(); var ngIfEl = fixture.debugElement.children[0]; @@ -343,7 +343,7 @@ function declareTests({useJit}: {useJit: boolean}) { expect(someViewport.container.length).toBe(2); expect(ngIfEl.children.length).toBe(2); - fixture.debugElement.componentInstance.ctxBoolProp = false; + fixture.componentInstance.ctxBoolProp = false; fixture.detectChanges(); expect(someViewport.container.length).toBe(2); @@ -356,7 +356,7 @@ function declareTests({useJit}: {useJit: boolean}) { TestBed.overrideComponent(MyComp, {set: {template}}); const fixture = TestBed.createComponent(MyComp); - var childNodesOfWrapper = getDOM().childNodes(fixture.debugElement.nativeElement); + var childNodesOfWrapper = getDOM().childNodes(fixture.nativeElement); expect(childNodesOfWrapper.length).toBe(1); expect(getDOM().isCommentNode(childNodesOfWrapper[0])).toBe(true); }); @@ -370,7 +370,7 @@ function declareTests({useJit}: {useJit: boolean}) { fixture.detectChanges(); - var childNodesOfWrapper = getDOM().childNodes(fixture.debugElement.nativeElement); + var childNodesOfWrapper = getDOM().childNodes(fixture.nativeElement); // 1 template + 2 copies. expect(childNodesOfWrapper.length).toBe(3); expect(childNodesOfWrapper[1]).toHaveText('hello'); @@ -390,10 +390,10 @@ function declareTests({useJit}: {useJit: boolean}) { TestBed.overrideComponent(MyComp, {set: {template}}); const fixture = TestBed.createComponent(MyComp); - fixture.debugElement.componentInstance.ctxProp = 'From myComp'; + fixture.componentInstance.ctxProp = 'From myComp'; fixture.detectChanges(); - expect(fixture.debugElement.nativeElement) + expect(fixture.nativeElement) .toHaveText('TOOLBAR(From myComp,From toolbar,Component with an injected host)'); }); @@ -428,7 +428,7 @@ function declareTests({useJit}: {useJit: boolean}) { fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('hello|hello|hello'); + expect(fixture.nativeElement).toHaveText('hello|hello|hello'); }); it('should assign two component instances each with a ref-', () => { @@ -498,7 +498,7 @@ function declareTests({useJit}: {useJit: boolean}) { fixture.detectChanges(); // Get the element at index 2, since index 0 is the