@@ -2,6 +2,7 @@ import {async, ComponentFixture, TestBed} from '@angular/core/testing';
22
33import { ComponentUnderTestComponent } from './component-under-test.component' ;
44import { Component } from "@angular/core" ;
5+ import { ViewChild } from "@angular/core" ;
56
67describe ( 'ComponentUnderTestComponent' , ( ) => {
78 let testHostComponent : TestHostComponent ;
@@ -20,25 +21,22 @@ describe('ComponentUnderTestComponent', () => {
2021 } ) ;
2122
2223 it ( 'should show TEST INPUT' , ( ) => {
23- testHostComponent . setInput ( 'test input' ) ;
24+ testHostComponent . componentUnderTestComponent . input = 'test input' ;
2425 testHostFixture . detectChanges ( ) ;
2526 expect ( testHostFixture . nativeElement . querySelector ( 'div' ) . innerText ) . toEqual ( 'TEST INPUT' ) ;
2627 } ) ;
2728
2829 it ( 'should show DIFFERENT TEST INPUT' , ( ) => {
29- testHostComponent . setInput ( 'different test input' ) ;
30+ testHostComponent . componentUnderTestComponent . input = 'different test input' ;
3031 testHostFixture . detectChanges ( ) ;
3132 expect ( testHostFixture . nativeElement . querySelector ( 'div' ) . innerText ) . toEqual ( 'DIFFERENT TEST INPUT' ) ;
3233 } ) ;
3334 @Component ( {
3435 selector : `host-component` ,
35- template : `<component-under-test [input]="input" ></component-under-test>`
36+ template : `<component-under-test></component-under-test>`
3637 } )
3738 class TestHostComponent {
38- private input : string ;
39-
40- setInput ( newInput : string ) {
41- this . input = newInput ;
42- }
39+ @ViewChild ( ComponentUnderTestComponent )
40+ public componentUnderTestComponent : ComponentUnderTestComponent ;
4341 }
4442} ) ;
0 commit comments