8000 chore(test): simplify test file (#2839) · oneiltdev/angular-cli@150b3b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 150b3b0

Browse files
authored
chore(test): simplify test file (angular#2839)
There is no need to have System typings or asynchronously load the testing modules.
1 parent b7da470 commit 150b3b0

File tree

2 files changed

+16
-29
lines changed

2 files changed

+16
-29
lines changed

packages/angular-cli/blueprints/ng2/files/__path__/test.ts

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import 'zone.js/dist/sync-test';
66
import 'zone.js/dist/jasmine-patch';
77
import 'zone.js/dist/async-test';
88
import 'zone.js/dist/fake-async-test';
9+
import { getTestBed } from '@angular/core/testing';
10+
import {
11+
BrowserDynamicTestingModule,
12+
platformBrowserDynamicTesting
13+
} from '@angular/platform-browser-dynamic/testing';
914

1015
// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
1116
declare var __karma__: any;
@@ -14,30 +19,14 @@ declare var require: any;
1419
// Prevent Karma from running prematurely.
1520
__karma__.loaded = function () {};
1621

17-
18-
Promise.all([
19-
System.import('@angular/core/testing'),
20-
System.import('@angular/platform-browser-dynamic/testing')
21-
])
22-
// First, initialize the Angular testing environment.
23-
.then(([testing, testingBrowser]) => {
24-
testing.getTestBed().initTestEnvironment(
25-
testingBrowser.BrowserDynamicTestingModule,
26-
testingBrowser.platformBrowserDynamicTesting()
27-
);
28-
})
29-
// Then we find all the tests.
30-
.then(() => require.context('./', true, /\.spec\.ts/))
31-
// And load the modules.
32-
.then(context => {
33-
try {
34-
return context.keys().map(context);
35-
} catch (e) {
36-
if (console) {
37-
console.error(e.message, e.stack);
38-
}
39-
throw e;
40-
}
41-
})
42-
// Finally, start Karma to run the tests.
43-
.then(__karma__.start, __karma__.error);
22+
// First, initialize the Angular testing environment.
23+
getTestBed().initTestEnvironment(
24+
BrowserDynamicTestingModule,
25+
platformBrowserDynamicTesting()
26+
);
27+
// Then we find all the tests.
28+
let context = require.context('./', true, /\.spec\.ts/);
29+
// And load the modules.
30+
context.keys().map(context);
31+
// Finally, start Karma to run the tests.
32+
__karma__.start();
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
// Typings reference file, you can add your own global typings here
22
// https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html
3-
4-
declare var System: any;

0 commit comments

Comments
 (0)
0