From 9934f618b5d0a960ca3a64eb4221d1ca05aeb981 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Thu, 24 Aug 2017 16:25:23 +0100 Subject: [PATCH] Got initial spec file passing --- src/app/app.component.spec.ts | 54 +++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 13c632d..1051610 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -1,32 +1,42 @@ -import { TestBed, async } from '@angular/core/testing'; +import { TestBed, ComponentFixture, async } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; +import { DebugElement } from '@angular/core'; +import { By } from '@angular/platform-browser'; + +// Items under test import { AppComponent } from './app.component'; describe('AppComponent', () => { - beforeEach(() => { - TestBed.configureTestingModule({ - declarations: [ - AppComponent - ], - }); - TestBed.compileComponents(); - }); + let fixture: ComponentFixture; + let app: AppComponent; + let de: DebugElement; + let appDocument: any; + + beforeEach(async(() => { + TestBed + .configureTestingModule({ + declarations: [ + AppComponent + ], + imports: [ + RouterTestingModule.withRoutes( + [{path: '', component: AppComponent}] + ) + ] + }) + .compileComponents(); + + fixture = TestBed.createComponent(AppComponent); + app = fixture.componentInstance; + de = fixture.debugElement; + appDocument = de.nativeElement; + })); it('should create the app', async(() => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.debugElement.componentInstance; expect(app).toBeTruthy(); })); - it(`should have as title 'app works!'`, async(() => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.debugElement.componentInstance; - expect(app.title).toEqual('app works!'); - })); - - it('should render title in a h1 tag', async(() => { - const fixture = TestBed.createComponent(AppComponent); - fixture.detectChanges(); - const compiled = fixture.debugElement.nativeElement; - expect(compiled.querySelector('h1').textContent).toContain('app works!'); + it('should have a router-outlet', async(() => { + expect(appDocument.querySelector('router-outlet')).toBeTruthy(); })); });