From 1d932c89b1426219410e77c2f27363765c1e2ea1 Mon Sep 17 00:00:00 2001 From: taumechanica Date: Mon, 6 Feb 2017 22:14:18 +0300 Subject: [PATCH] Fix tests. --- src/app/app.component.spec.ts | 17 ++++++++++------- .../steps-container.component.spec.ts | 18 ++++++++++++++---- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 3c53ee1..f4d1c0b 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -1,14 +1,13 @@ /* tslint:disable:no-unused-variable */ +import { async, fakeAsync, tick, TestBed } from '@angular/core/testing'; -import { TestBed, async } from '@angular/core/testing'; +import { AppModule } from './app.module'; import { AppComponent } from './app.component'; describe('AppComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [ - AppComponent - ], + imports: [AppModule] }); TestBed.compileComponents(); }); @@ -19,17 +18,21 @@ describe('AppComponent', () => { expect(app).toBeTruthy(); })); - it('should have a step components array of length 3', async(() => { + it('should have a step components array of length 3', fakeAsync(() => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.debugElement.componentInstance; - expect(app.stepComponents).toEqual(jasmine.any([])); + app.ngOnInit(); + tick(); + + expect(app.stepComponents).toEqual(jasmine.any(Array)); expect(app.stepComponents.length).toEqual(3); })); it('should contain a step-container compoent', async(() => { const fixture = TestBed.createComponent(AppComponent); fixture.detectChanges(); + const compiled = fixture.debugElement.nativeElement; - expect(compiled.querySelector('app-steps-container').length).toBe(1); + expect(compiled.querySelectorAll('app-steps-container').length).toBe(1); })); }); diff --git a/src/app/steps-container/steps-container.component.spec.ts b/src/app/steps-container/steps-container.component.spec.ts index 47bf3d4..756d84b 100644 --- a/src/app/steps-container/steps-container.component.spec.ts +++ b/src/app/steps-container/steps-container.component.spec.ts @@ -1,5 +1,9 @@ /* tslint:disable:no-unused-variable */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { async, fakeAsync, tick, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AppModule } from '../app.module'; +import { AppComponent } from '../app.component'; + import { By } from '@angular/platform-browser'; import { DebugElement } from '@angular/core'; @@ -11,16 +15,22 @@ describe('StepsContainerComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ StepsContainerComponent ] + imports: [AppModule] }) .compileComponents(); })); - beforeEach(() => { + beforeEach(fakeAsync(() => { + const appFixture = TestBed.createComponent(AppComponent); + const app = appFixture.debugElement.componentInstance; + app.ngOnInit(); + tick(); + fixture = TestBed.createComponent(StepsContainerComponent); component = fixture.componentInstance; + component.steps = app.stepComponents; fixture.detectChanges(); - }); + })); it('should create', () => { expect(component).toBeTruthy();