|
1 | 1 | /* tslint:disable:no-unused-variable */ |
2 | 2 | import { AppComponent } from './app.component'; |
3 | 3 |
|
4 | | -import { TestBed } from '@angular/core/testing'; |
5 | | - |
| 4 | +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; |
6 | 5 | import { By } from '@angular/platform-browser'; |
| 6 | +import { DebugElement } from '@angular/core'; |
7 | 7 |
|
8 | 8 | //////// SPECS ///////////// |
| 9 | +describe('AppComponent', function () { |
| 10 | + let de: DebugElement; |
| 11 | + let comp: AppComponent; |
| 12 | + let fixture: ComponentFixture<AppComponent>; |
| 13 | + |
| 14 | + beforeEach(async(() => { |
| 15 | + TestBed.configureTestingModule({ |
| 16 | + declarations: [ AppComponent ] |
| 17 | + }) |
| 18 | + .compileComponents(); |
| 19 | + })); |
9 | 20 |
|
10 | | -/// Delete this |
11 | | -describe('Smoke test', () => { |
12 | | - it('should run a passing test', () => { |
13 | | - expect(true).toEqual(true, 'should pass'); |
14 | | - }); |
15 | | -}); |
16 | | - |
17 | | -describe('AppComponent with TCB', function () { |
18 | 21 | beforeEach(() => { |
19 | | - TestBed.configureTestingModule({declarations: [AppComponent]}); |
| 22 | + fixture = TestBed.createComponent(AppComponent); |
| 23 | + comp = fixture.componentInstance; |
| 24 | + de = fixture.debugElement.query(By.css('h1')); |
20 | 25 | }); |
21 | 26 |
|
22 | | - it('should instantiate component', () => { |
23 | | - let fixture = TestBed.createComponent(AppComponent); |
24 | | - expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent'); |
25 | | - }); |
| 27 | + it('should create component', () => expect(comp).toBeDefined() ); |
26 | 28 |
|
27 | 29 | it('should have expected <h1> text', () => { |
28 | | - let fixture = TestBed.createComponent(AppComponent); |
29 | 30 | fixture.detectChanges(); |
30 | | - |
31 | | - let h1 = fixture.debugElement.query(el => el.name === 'h1').nativeElement; // it works |
32 | | - |
33 | | - h1 = fixture.debugElement.query(By.css('h1')).nativeElement; // preferred |
34 | | - |
35 | | - expect(h1.innerText).toMatch(/angular app/i, '<h1> should say something about "Angular App"'); |
| 31 | + const h1 = de.nativeElement; |
| 32 | + expect(h1.innerText).toMatch(/angular app/i, |
| 33 | + '<h1> should say something about "Angular App"'); |
36 | 34 | }); |
37 | 35 | }); |
0 commit comments