Skip to content

Commit 7608c27

Browse files
committed
Even less boilerplate
1 parent ce2bb8f commit 7608c27

20 files changed

+467
-895
lines changed

libraries/angular/karma.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ module.exports = function (config) {
4343
// RxJs.
4444
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
4545
{ pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },
46-
'tests.webpack.ts'
46+
'tests.webpack.js'
4747
],
4848
preprocessors: {
49-
'tests.webpack.ts': ['webpack', 'sourcemap'] // preprocess with webpack and our sourcemap loader
49+
'tests.webpack.js': ['webpack', 'sourcemap'] // preprocess with webpack and our sourcemap loader
5050
},
5151
mime: {
5252
'text/x-typescript': ['ts']

libraries/angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
],
4343
"files": [
4444
"karma.conf.js",
45-
"tests.webpack.ts",
45+
"tests.webpack.js",
4646
"tsconfig.json",
4747
"src",
4848
"meta"

libraries/angular/src/advanced-tests.js

Lines changed: 0 additions & 69 deletions
This file was deleted.

libraries/angular/src/basic-tests.js renamed to libraries/angular/tests.webpack.js

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,45 @@
1515
* limitations under the License.
1616
*/
1717

18+
import 'reflect-metadata/Reflect';
19+
import 'zone.js/dist/zone';
20+
import 'zone.js/dist/webapis-shadydom'; // https://github.com/angular/zone.js/pull/784
21+
import 'zone.js/dist/long-stack-trace-zone';
22+
import 'zone.js/dist/proxy';
23+
import 'zone.js/dist/sync-test';
24+
import 'zone.js/dist/mocha-patch';
25+
import 'zone.js/dist/async-test';
26+
import 'zone.js/dist/fake-async-test';
27+
import { getTestBed } from '@angular/core/testing';
28+
import {
29+
BrowserDynamicTestingModule,
30+
platformBrowserDynamicTesting
31+
} from '@angular/platform-browser-dynamic/testing';
1832
import { CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
19-
import { TestBed } from "@angular/core/testing";
20-
2133
import {
22-
ComponentWithoutChildren,
2334
ComponentWithChildren,
24-
ComponentWithChildrenRerender,
25-
ComponentWithDifferentViews,
26-
ComponentWithProperties,
27-
ComponentWithUnregistered,
28-
ComponentWithImperativeEvent,
29-
ComponentWithDeclarativeEvent
30-
} from "./components";
35+
ComponentWithChildrenRerender, ComponentWithDeclarativeEvent,
36+
ComponentWithDifferentViews, ComponentWithImperativeEvent,
37+
ComponentWithoutChildren, ComponentWithProperties, ComponentWithUnregistered
38+
} from "./src/components";
39+
40+
import basicTests from "basic-tests";
41+
import advancedTests from "advanced-tests";
42+
43+
44+
// Prevent Karma from running prematurely.
45+
__karma__.loaded = function () {};
46+
47+
// First, initialize the Angular testing environment.
48+
getTestBed().initTestEnvironment(
49+
BrowserDynamicTestingModule,
50+
platformBrowserDynamicTesting()
51+
);
52+
// Run basic and advanced tests through Karma
3153

32-
import tests from 'basic-tests';
3354

3455
beforeEach(function() {
35-
TestBed.configureTestingModule({
56+
getTestBed().configureTestingModule({
3657
declarations: [
3758
ComponentWithoutChildren,
3859
ComponentWithChildren,
@@ -48,14 +69,14 @@ beforeEach(function() {
4869
});
4970

5071
function render(Component) {
51-
const fixture = TestBed.createComponent(Component);
72+
const fixture = getTestBed().createComponent(Component);
5273
fixture.detectChanges();
5374
const el = fixture.debugElement.nativeElement;
5475
const wc = el.querySelector('#wc');
5576
return { wc, fixture }
5677
}
5778

58-
tests({
79+
const renderers = {
5980
renderComponentWithoutChildren() {
6081
return render(ComponentWithoutChildren);
6182
},
@@ -86,5 +107,19 @@ tests({
86107
fixture.detectChanges();
87108
}
88109
return { wc, fixture, click };
110+
},
111+
renderComponentWithDeclarativeEvent() {
112+
const { wc, fixture } = render(ComponentWithDeclarativeEvent);
113+
function click() {
114+
wc.click();
115+
fixture.detectChanges();
116+
}
117+
return { wc, fixture, click };
89118
}
90-
});
119+
};
120+
121+
basicTests(renderers);
122+
advancedTests(renderers);
123+
124+
// Finally, start Karma to run the tests.
125+
__karma__.start();

libraries/angular/tests.webpack.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.

libraries/angularjs/src/advanced-tests.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

libraries/angularjs/src/basic-tests.js

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)