From 8fb696f25a861df6949a29eb1915f275cf71aff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesu=CC=81s=20Rodri=CC=81guez?= Date: Wed, 17 Aug 2016 14:15:49 +0200 Subject: [PATCH] chore: update specs to TestBed --- app/app.component.spec.ts | 38 +++++++++++++++----------------------- karma-test-shim.js | 33 +++++++++++++++------------------ karma.conf.js | 3 ++- 3 files changed, 32 insertions(+), 42 deletions(-) diff --git a/app/app.component.spec.ts b/app/app.component.spec.ts index 0b9c23987..211fadfda 100644 --- a/app/app.component.spec.ts +++ b/app/app.component.spec.ts @@ -1,13 +1,9 @@ /* tslint:disable:no-unused-variable */ import { AppComponent } from './app.component'; -import { async, inject } from '@angular/core/testing'; - -import { TestComponentBuilder } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -import { provide } from '@angular/core'; -import { ViewMetadata } from '@angular/core'; //////// SPECS ///////////// @@ -19,27 +15,23 @@ describe('Smoke test', () => { }); describe('AppComponent with TCB', function () { + beforeEach(() => { + TestBed.configureTestingModule({declarations: [AppComponent]}); + }); - it('should instantiate component', - async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { - - tcb.createAsync(AppComponent).then(fixture => { - expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent'); - }); - }))); - - it('should have expected

text', - async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { - - tcb.createAsync(AppComponent).then(fixture => { - // fixture.detectChanges(); // would need to resolve a binding but we don't have a binding + it('should instantiate component', () => { + let fixture = TestBed.createComponent(AppComponent); + expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent'); + }); - let h1 = fixture.debugElement.query(el => el.name === 'h1').nativeElement; // it works + it('should have expected

text', () => { + let fixture = TestBed.createComponent(AppComponent); + fixture.detectChanges(); - h1 = fixture.debugElement.query(By.css('h1')).nativeElement; // preferred + let h1 = fixture.debugElement.query(el => el.name === 'h1').nativeElement; // it works - expect(h1.innerText).toMatch(/angular 2 app/i, '

should say something about "Angular 2 App"'); - }); + h1 = fixture.debugElement.query(By.css('h1')).nativeElement; // preferred - }))); + expect(h1.innerText).toMatch(/angular 2 app/i, '

should say something about "Angular 2 App"'); + }); }); diff --git a/karma-test-shim.js b/karma-test-shim.js index ec50e1ff6..9ad166440 100644 --- a/karma-test-shim.js +++ b/karma-test-shim.js @@ -28,27 +28,24 @@ System.config({ }); System.import('systemjs.config.js') - .then(function () { - return Promise.all([ + .then(() => Promise.all([ System.import('@angular/core/testing'), System.import('@angular/platform-browser-dynamic/testing') - ]) - }) - .then(function (providers) { - var testing = providers[0]; - var testingBrowser = providers[1]; - - testing.setBaseTestProviders( - testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, - testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS); + ])) + .then((providers) => { + var coreTesting = providers[0]; + var browserTesting = providers[1]; + coreTesting.TestBed.initTestEnvironment( + browserTesting.BrowserDynamicTestingModule, + browserTesting.platformBrowserDynamicTesting()); }) - .then(function() { - // Finally, load all spec files. - // This will run the tests directly. - return Promise.all( - allSpecFiles.map(function (moduleName) { - return System.import(moduleName); - })); + .then(function () { + // Finally, load all spec files. + // This will run the tests directly. + return Promise.all( + allSpecFiles.map(function (moduleName) { + return System.import(moduleName); + })); }) .then(__karma__.start, __karma__.error); diff --git a/karma.conf.js b/karma.conf.js index faa52df98..30228f41c 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -30,9 +30,10 @@ module.exports = function(config) { // Reflect and Zone.js 'node_modules/reflect-metadata/Reflect.js', 'node_modules/zone.js/dist/zone.js', - 'node_modules/zone.js/dist/jasmine-patch.js', 'node_modules/zone.js/dist/async-test.js', 'node_modules/zone.js/dist/fake-async-test.js', + 'node_modules/zone.js/dist/sync-test.js', + 'node_modules/zone.js/dist/proxy-zone.js', // RxJs. { pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },