Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 8fb696f

Browse files
committed
chore: update specs to TestBed
1 parent c4cd634 commit 8fb696f

File tree

3 files changed

+32
-42
lines changed

3 files changed

+32
-42
lines changed

app/app.component.spec.ts

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
/* tslint:disable:no-unused-variable */
22
import { AppComponent } from './app.component';
33

4-
import { async, inject } from '@angular/core/testing';
5-
6-
import { TestComponentBuilder } from '@angular/core/testing';
4+
import { TestBed } from '@angular/core/testing';
75

86
import { By } from '@angular/platform-browser';
9-
import { provide } from '@angular/core';
10-
import { ViewMetadata } from '@angular/core';
117

128
//////// SPECS /////////////
139

@@ -19,27 +15,23 @@ describe('Smoke test', () => {
1915
});
2016

2117
describe('AppComponent with TCB', function () {
18+
beforeEach(() => {
19+
TestBed.configureTestingModule({declarations: [AppComponent]});
20+
});
2221

23-
it('should instantiate component',
24-
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
25-
26-
tcb.createAsync(AppComponent).then(fixture => {
27-
expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent');
28-
});
29-
})));
30-
31-
it('should have expected <h1> text',
32-
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
33-
34-
tcb.createAsync(AppComponent).then(fixture => {
35-
// fixture.detectChanges(); // would need to resolve a binding but we don't have a binding
22+
it('should instantiate component', () => {
23+
let fixture = TestBed.createComponent(AppComponent);
24+
expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent');
25+
});
3626

37-
let h1 = fixture.debugElement.query(el => el.name === 'h1').nativeElement; // it works
27+
it('should have expected <h1> text', () => {
28+
let fixture = TestBed.createComponent(AppComponent);
29+
fixture.detectChanges();
3830

39-
h1 = fixture.debugElement.query(By.css('h1')).nativeElement; // preferred
31+
let h1 = fixture.debugElement.query(el => el.name === 'h1').nativeElement; // it works
4032

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

44-
})));
35+
expect(h1.innerText).toMatch(/angular 2 app/i, '<h1> should say something about "Angular 2 App"');
36+
});
4537
});

karma-test-shim.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,24 @@ System.config({
2828
});
2929

3030
System.import('systemjs.config.js')
31-
.then(function () {
32-
return Promise.all([
31+
.then(() => Promise.all([
3332
System.import('@angular/core/testing'),
3433
System.import('@angular/platform-browser-dynamic/testing')
35-
])
36-
})
37-
.then(function (providers) {
38-
var testing = providers[0];
39-
var testingBrowser = providers[1];
40-
41-
testing.setBaseTestProviders(
42-
testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
43-
testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
34+
]))
35+
.then((providers) => {
36+
var coreTesting = providers[0];
37+
var browserTesting = providers[1];
38+
coreTesting.TestBed.initTestEnvironment(
39+
browserTesting.BrowserDynamicTestingModule,
40+
browserTesting.platformBrowserDynamicTesting());
4441

4542
})
46-
.then(function() {
47-
// Finally, load all spec files.
48-
// This will run the tests directly.
49-
return Promise.all(
50-
allSpecFiles.map(function (moduleName) {
51-
return System.import(moduleName);
52-
}));
43+
.then(function () {
44+
// Finally, load all spec files.
45+
// This will run the tests directly.
46+
return Promise.all(
47+
allSpecFiles.map(function (moduleName) {
48+
return System.import(moduleName);
49+
}));
5350
})
5451
.then(__karma__.start, __karma__.error);

karma.conf.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ module.exports = function(config) {
3030
// Reflect and Zone.js
3131
'node_modules/reflect-metadata/Reflect.js',
3232
'node_modules/zone.js/dist/zone.js',
33-
'node_modules/zone.js/dist/jasmine-patch.js',
3433
'node_modules/zone.js/dist/async-test.js',
3534
'node_modules/zone.js/dist/fake-async-test.js',
35+
'node_modules/zone.js/dist/sync-test.js',
36+
'node_modules/zone.js/dist/proxy-zone.js',
3637

3738
// RxJs.
3839
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },

0 commit comments

Comments
 (0)