|
1 | 1 | import {async, ComponentFixture, TestBed} from '@angular/core/testing'; |
2 | 2 |
|
3 | 3 | import {ComponentUnderTestComponent} from './component-under-test.component'; |
| 4 | +import {Component} from "@angular/core"; |
4 | 5 |
|
5 | 6 | describe('ComponentUnderTestComponent', () => { |
6 | | - let component: ComponentUnderTestComponent; |
7 | | - let fixture: ComponentFixture<ComponentUnderTestComponent>; |
| 7 | + let testHostComponent: TestHostComponent; |
| 8 | + let testHostFixture: ComponentFixture<TestHostComponent>; |
8 | 9 |
|
9 | 10 | beforeEach(async(() => { |
10 | 11 | TestBed.configureTestingModule({ |
11 | | - declarations: [ComponentUnderTestComponent] |
| 12 | + declarations: [ComponentUnderTestComponent, TestHostComponent] |
12 | 13 | }) |
13 | 14 | .compileComponents(); |
14 | 15 | })); |
15 | 16 |
|
16 | 17 | beforeEach(() => { |
17 | | - fixture = TestBed.createComponent(ComponentUnderTestComponent); |
18 | | - component = fixture.componentInstance; |
19 | | - fixture.detectChanges(); |
| 18 | + testHostFixture = TestBed.createComponent(TestHostComponent); |
| 19 | + testHostComponent = testHostFixture.componentInstance; |
| 20 | + testHostFixture.detectChanges(); |
20 | 21 | }); |
21 | 22 |
|
22 | 23 | it('should be created', () => { |
23 | | - expect(component).toBeTruthy(); |
| 24 | + expect(testHostComponent).toBeTruthy(); |
24 | 25 | }); |
25 | 26 |
|
26 | 27 | it('should show TEST INPUT', () => { |
27 | | - component.input = 'test input'; |
28 | | - component.processInput(); |
29 | | - fixture.detectChanges(); |
30 | | - expect(fixture.nativeElement.querySelector('div').innerText).toEqual('TEST INPUT'); |
| 28 | + expect(testHostFixture.nativeElement.querySelector('div').innerText).toEqual('TEST INPUT'); |
31 | 29 | }); |
| 30 | + |
| 31 | + @Component({ |
| 32 | + selector: `host-component`, |
| 33 | + template: `<component-under-test input="test input"></component-under-test>` |
| 34 | + }) |
| 35 | + class TestHostComponent { |
| 36 | + } |
32 | 37 | }); |
0 commit comments