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

Commit a6a698f

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

File tree

2 files changed

+31
-45
lines changed

2 files changed

+31
-45
lines changed

app/app.component.spec.ts

+15-23
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

+16-22
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,20 @@ System.config({
2929

3030
System.import('systemjs.config.js')
3131
.then(function () {
32-
return Promise.all([
33-
System.import('@angular/core/testing'),
34-
System.import('@angular/platform-browser-dynamic/testing')
35-
])
32+
System.import('@angular/core/testing')
33+
.then(function (coreTesting) {
34+
return System.import('@angular/platform-browser-dynamic/testing').then(function (browserTesting) {
35+
coreTesting.TestBed.initTestEnvironment(
36+
browserTesting.BrowserDynamicTestingModule, browserTesting.platformBrowserDynamicTesting());
37+
});
38+
})
39+
.then(function () {
40+
// Finally, load all spec files.
41+
// This will run the tests directly.
42+
return Promise.all(
43+
allSpecFiles.map(function (moduleName) {
44+
return System.import(moduleName);
45+
}));
46+
})
47+
.then(__karma__.start, __karma__.error);
3648
})
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);
44-
45-
})
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-
}));
53-
})
54-
.then(__karma__.start, __karma__.error);

0 commit comments

Comments
 (0)