Got initial spec file passing
This commit is contained in:
parent
c46e91e795
commit
9934f618b5
1 changed files with 32 additions and 22 deletions
|
@ -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';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
describe('AppComponent', () => {
|
describe('AppComponent', () => {
|
||||||
beforeEach(() => {
|
let fixture: ComponentFixture<AppComponent>;
|
||||||
TestBed.configureTestingModule({
|
let app: AppComponent;
|
||||||
|
let de: DebugElement;
|
||||||
|
let appDocument: any;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed
|
||||||
|
.configureTestingModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
AppComponent
|
AppComponent
|
||||||
],
|
],
|
||||||
});
|
imports: [
|
||||||
TestBed.compileComponents();
|
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(() => {
|
it('should create the app', async(() => {
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
|
||||||
const app = fixture.debugElement.componentInstance;
|
|
||||||
expect(app).toBeTruthy();
|
expect(app).toBeTruthy();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it(`should have as title 'app works!'`, async(() => {
|
it('should have a router-outlet', async(() => {
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
expect(appDocument.querySelector('router-outlet')).toBeTruthy();
|
||||||
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!');
|
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue