Got initial spec file passing

This commit is contained in:
Tom Bloor 2017-08-24 16:25:23 +01:00
parent c46e91e795
commit 9934f618b5

View file

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