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

Commit 4a48f96

Browse files
committed
refactor(test): update to jasmine 2.0 and refactor tests
1 parent 65dab7a commit 4a48f96

14 files changed

+309
-583
lines changed

Diff for: package.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
"url": "https://github.com/angular/zone.js/issues"
2121
},
2222
"devDependencies": {
23-
"karma": "0.12.16",
24-
"karma-sauce-launcher": "~0.2.0",
25-
"karma-jasmine": "0.1.5",
26-
"karma-chrome-launcher": "^0.1.4",
27-
"karma-coverage": "~0.1.4",
28-
"karma-firefox-launcher": "~0.1.3",
29-
"karma-safari-launcher": "^0.1.1"
23+
"jasmine-core": "^2.2.0",
24+
"karma": "^0.12.31",
25+
"karma-chrome-launcher": "^0.1.7",
26+
"karma-firefox-launcher": "^0.1.4",
27+
"karma-jasmine": "^0.3.5",
28+
"karma-safari-launcher": "^0.1.1",
29+
"karma-sauce-launcher": "^0.2.10",
30+
"nodejs-websocket": "^1.2.0"
3031
}
3132
}

Diff for: test/counting-zone.disabled.js

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
'use strict';
2+
3+
describe('Zone.countingZone', function () {
4+
function makeCountingZone() {
5+
return zone.fork(Zone.longStackTraceZone).
6+
fork(Zone.countingZone);
7+
}
8+
9+
it('should flush at the end of a run', function (done) {
10+
makeCountingZone().fork({
11+
onFlush: done
12+
}).run(function () { });
13+
});
14+
15+
16+
it('should work with setTimeout', function (done) {
17+
var countingZone = makeCountingZone();
18+
countingZone.run(function () {
19+
setTimeout(function () {
20+
expect(countingZone.counter()).toBe(0);
21+
done();
22+
}, 0);
23+
expect(countingZone.counter()).toBe(1);
24+
});
25+
});
26+
27+
28+
it('should work with clearTimeout', function (done) {
29+
var countingZone = makeCountingZone();
30+
31+
makeCountingZone().run(function () {
32+
var id = setTimeout(function () {}, 0);
33+
expect(countingZone.counter()).toBe(1);
34+
clearTimeout(id);
35+
expect(countingZone.counter()).toBe(0);
36+
done();
37+
});
38+
});
39+
40+
41+
it('should work with setInterval', function (done) {
42+
var latch = 0,
43+
countingZone = makeCountingZone(),
44+
id;
45+
46+
countingZone.run(function () {
47+
expect(countingZone.counter()).toBe(0);
48+
49+
id = setInterval(function () {
50+
latch += 1;
51+
52+
// setInterval should run multiple times
53+
if (latch === 2) {
54+
finish();
55+
}
56+
}, 0);
57+
58+
expect(countingZone.counter()).toBe(1);
59+
});
60+
61+
function finish() {
62+
expect(countingZone.counter()).toBe(1);
63+
clearInterval(id);
64+
done();
65+
}
66+
});
67+
68+
69+
it('should work with clearInterval', function (done) {
70+
var id;
71+
countingZone.run(function () {
72+
id = setInterval(function () {
73+
latch += 1;
74+
}, 0);
75+
expect(countingZone.counter()).toBe(1);
76+
clearInterval(id);
77+
expect(countingZone.counter()).toBe(0);
78+
done();
79+
});
80+
});
81+
82+
83+
it('should work with addEventListener', function (done) {
84+
var elt = document.createElement('button');
85+
expect(countingZone.counter()).toBe(0);
86+
countingZone.run(main);
87+
88+
function main () {
89+
expect(countingZone.counter()).toBe(0);
90+
elt.addEventListener('click', onClick);
91+
expect(countingZone.counter()).toBe(1);
92+
93+
elt.click();
94+
function onClick () {
95+
expect(countingZone.counter()).toBe(1);
96+
elt.removeEventListener('click', onClick);
97+
expect(countingZone.counter()).toBe(0);
98+
99+
done();
100+
clicked = true;
101+
}
102+
103+
expect(countingZone.counter()).toBe(0);
104+
}
105+
});
106+
});

Diff for: test/counting-zone.spec.js

-123
This file was deleted.

Diff for: test/long-stack-trace-zone.spec.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,39 @@ describe('longStackTraceZone', function () {
1111

1212
beforeEach(function () {
1313
log = [];
14-
jasmine.Clock.useMock();
1514
});
1615

17-
it('should produce long stack traces', function () {
16+
it('should produce long stack traces', function (done) {
1817
lstz.run(function () {
1918
setTimeout(function () {
2019
setTimeout(function () {
20+
setTimeout(function () {
21+
expect(log[0]).toBe('Error: hello');
22+
expect(log[1].split('--- ').length).toBe(4);
23+
done();
24+
}, 0);
2125
throw new Error('hello');
2226
}, 0);
2327
}, 0);
2428
});
25-
26-
jasmine.Clock.tick(0);
27-
28-
expect(log[0]).toBe('Error: hello');
29-
expect(log[1].split('--- ').length).toBe(4);
3029
});
3130

3231

33-
it('should filter based on stackFramesFilter', function () {
32+
it('should filter based on stackFramesFilter', function (done) {
3433
lstz.fork({
3534
stackFramesFilter: function (line) {
3635
return line.indexOf('jasmine.js') === -1;
3736
}
3837
}).run(function () {
3938
setTimeout(function () {
4039
setTimeout(function () {
40+
setTimeout(function () {
41+
expect(log[1]).not.toContain('jasmine.js');
42+
done();
43+
}, 0);
4144
throw new Error('hello');
4245
}, 0);
4346
}, 0);
4447
});
45-
46-
jasmine.Clock.tick(0);
47-
expect(log[1]).not.toContain('jasmine.js');
4848
});
4949
});

0 commit comments

Comments
 (0)