From 48a695e626898a4ed1ce3a9e56b1da946476e089 Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Fri, 26 Aug 2016 02:24:40 +0100 Subject: [PATCH] chore(tests): update specs with TestBed Close #1766 Close #1846 --- .../files/__path__/__name__.component.spec.ts | 4 +-- .../files/__path__/__name__.directive.spec.ts | 2 +- .../files/__path__/__name__.module.spec.ts | 1 + .../files/__path__/app/app.component.spec.ts | 33 +++++++++++++------ .../pipe/files/__path__/__name__.pipe.spec.ts | 2 +- .../files/__path__/__name__.service.spec.ts | 14 ++++---- 6 files changed, 34 insertions(+), 22 deletions(-) diff --git a/addon/ng2/blueprints/component/files/__path__/__name__.component.spec.ts b/addon/ng2/blueprints/component/files/__path__/__name__.component.spec.ts index 880bcc1c792f..e7ed84fac3d2 100644 --- a/addon/ng2/blueprints/component/files/__path__/__name__.component.spec.ts +++ b/addon/ng2/blueprints/component/files/__path__/__name__.component.spec.ts @@ -1,8 +1,6 @@ /* tslint:disable:no-unused-variable */ -import { By } from '@angular/platform-browser'; -import { DebugElement } from '@angular/core'; -import { addProviders, async, inject } from '@angular/core/testing'; +import { TestBed, async } from '@angular/core/testing'; import { <%= classifiedModuleName %>Component } from './<%= dasherizedModuleName %>.component'; describe('Component: <%= classifiedModuleName %>', () => { diff --git a/addon/ng2/blueprints/directive/files/__path__/__name__.directive.spec.ts b/addon/ng2/blueprints/directive/files/__path__/__name__.directive.spec.ts index 3e8c53f216af..481baeaa967c 100644 --- a/addon/ng2/blueprints/directive/files/__path__/__name__.directive.spec.ts +++ b/addon/ng2/blueprints/directive/files/__path__/__name__.directive.spec.ts @@ -1,6 +1,6 @@ /* tslint:disable:no-unused-variable */ -import { addProviders, async, inject } from '@angular/core/testing'; +import { TestBed, async } from '@angular/core/testing'; import { <%= classifiedModuleName %> } from './<%= dasherizedModuleName %>.directive'; describe('Directive: <%= classifiedModuleName %>', () => { diff --git a/addon/ng2/blueprints/module/files/__path__/__name__.module.spec.ts b/addon/ng2/blueprints/module/files/__path__/__name__.module.spec.ts index d33c39399fed..12ed52ce06d2 100644 --- a/addon/ng2/blueprints/module/files/__path__/__name__.module.spec.ts +++ b/addon/ng2/blueprints/module/files/__path__/__name__.module.spec.ts @@ -1,5 +1,6 @@ /* tslint:disable:no-unused-variable */ +import { TestBed, async } from '@angular/core/testing'; import <%= classifiedModuleName %>Module from './<%= dasherizedModuleName %>.module'; describe('<%= classifiedModuleName %>Module', () => { diff --git a/addon/ng2/blueprints/ng2/files/__path__/app/app.component.spec.ts b/addon/ng2/blueprints/ng2/files/__path__/app/app.component.spec.ts index be843756c906..dfdebd7b9d19 100644 --- a/addon/ng2/blueprints/ng2/files/__path__/app/app.component.spec.ts +++ b/addon/ng2/blueprints/ng2/files/__path__/app/app.component.spec.ts @@ -1,20 +1,33 @@ /* tslint:disable:no-unused-variable */ -import { addProviders, async, inject } from '@angular/core/testing'; +import { TestBed, async } from '@angular/core/testing'; import { AppComponent } from './app.component'; describe('App: <%= jsComponentName %>', () => { beforeEach(() => { - addProviders([AppComponent]); + TestBed.configureTestingModule({ + declarations: [ + AppComponent + ], + }); }); - it('should create the app', - inject([AppComponent], (app: AppComponent) => { - expect(app).toBeTruthy(); - })); + it('should create the app', async(() => { + let fixture = TestBed.createComponent(AppComponent); + let app = fixture.debugElement.componentInstance; + expect(app).toBeTruthy(); + })); - it('should have as title \'app works!\'', - inject([AppComponent], (app: AppComponent) => { - expect(app.title).toEqual('app works!'); - })); + it(`should have as title 'app works!'`, async(() => { + let fixture = TestBed.createComponent(AppComponent); + let app = fixture.debugElement.componentInstance; + expect(app.title).toEqual('app works!'); + })); + + it('should render title in a h1 tag', async(() => { + let fixture = TestBed.createComponent(AppComponent); + fixture.detectChanges(); + let compiled = fixture.debugElement.nativeElement; + expect(compiled.querySelector('h1').textContent).toContain('app works!'); + })); }); diff --git a/addon/ng2/blueprints/pipe/files/__path__/__name__.pipe.spec.ts b/addon/ng2/blueprints/pipe/files/__path__/__name__.pipe.spec.ts index 43c6624f5a83..afc35fb4ff68 100644 --- a/addon/ng2/blueprints/pipe/files/__path__/__name__.pipe.spec.ts +++ b/addon/ng2/blueprints/pipe/files/__path__/__name__.pipe.spec.ts @@ -1,6 +1,6 @@ /* tslint:disable:no-unused-variable */ -import { addProviders, async, inject } from '@angular/core/testing'; +import { TestBed, async } from '@angular/core/testing'; import { <%= classifiedModuleName %>Pipe } from './<%= dasherizedModuleName %>.pipe'; describe('Pipe: <%= classifiedModuleName %>', () => { diff --git a/addon/ng2/blueprints/service/files/__path__/__name__.service.spec.ts b/addon/ng2/blueprints/service/files/__path__/__name__.service.spec.ts index e26a9250dce6..432cebe318c6 100644 --- a/addon/ng2/blueprints/service/files/__path__/__name__.service.spec.ts +++ b/addon/ng2/blueprints/service/files/__path__/__name__.service.spec.ts @@ -1,16 +1,16 @@ /* tslint:disable:no-unused-variable */ -import { addProviders, async, inject } from '@angular/core/testing'; +import { TestBed, async, inject } from '@angular/core/testing'; import { <%= classifiedModuleName %>Service } from './<%= dasherizedModuleName %>.service'; describe('Service: <%= classifiedModuleName %>', () => { beforeEach(() => { - addProviders([<%= classifiedModuleName %>Service]); + TestBed.configureTestingModule({ + providers: [<%= classifiedModuleName %>Service] + }); }); - it('should ...', - inject([<%= classifiedModuleName %>Service], - (service: <%= classifiedModuleName %>Service) => { - expect(service).toBeTruthy(); - })); + it('should ...', inject([<%= classifiedModuleName %>Service], (service: <%= classifiedModuleName %>Service) => { + expect(service).toBeTruthy(); + })); });