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(); })); });