5: Add In-app Navigation
[examples/angular-tour-of-heroes] / src / app / app.component.spec.ts
1 import { TestBed, async } from '@angular/core/testing';
2 import { AppComponent } from './app.component';
3 import { Component } from '@angular/core';
4
5 @Component({selector: 'router-outlet', template: ''})
6 class RouterOutletStubComponent { }
7
8 @Component({selector: 'app-messages', template: ''})
9 class MessagesStubComponent {}
10
11 describe('AppComponent', () => {
12   beforeEach(async(() => {
13     TestBed.configureTestingModule({
14       declarations: [
15         AppComponent,
16         RouterOutletStubComponent,
17         MessagesStubComponent
18       ],
19     }).compileComponents();
20   }));
21
22   it('should create the app', () => {
23     const fixture = TestBed.createComponent(AppComponent);
24     const app = fixture.debugElement.componentInstance;
25     expect(app).toBeTruthy();
26   });
27
28   it(`should have as title 'Tour of Heroes'`, () => {
29     const fixture = TestBed.createComponent(AppComponent);
30     const app = fixture.debugElement.componentInstance;
31     expect(app.title).toEqual('Tour of Heroes');
32   });
33
34   it(`should render the title 'Tour of Heroes'`, () => {
35     const fixture = TestBed.createComponent(AppComponent);
36     fixture.detectChanges();
37     const compiled = fixture.debugElement.nativeElement;
38     expect(compiled.querySelector('h1').textContent).toContain('Tour of Heroes');
39   });
40
41   it(`should render the link 'Heroes'`, () => {
42     const fixture = TestBed.createComponent(AppComponent);
43     fixture.detectChanges();
44     const compiled = fixture.debugElement.nativeElement;
45     expect(compiled.querySelector('nav > a:nth-child(1)').textContent).toContain('Dashboard');
46     expect(compiled.querySelector('nav > a:nth-child(2)').textContent).toContain('Heroes');
47   });
48 });