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

Commit

Permalink
refactor(test): update to jasmine 2.0 and refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
btford committed Feb 4, 2015
1 parent 65dab7a commit 4a48f96
Show file tree
Hide file tree
Showing 14 changed files with 309 additions and 583 deletions.
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
"url": "https://github.com/angular/zone.js/issues"
},
"devDependencies": {
"karma": "0.12.16",
"karma-sauce-launcher": "~0.2.0",
"karma-jasmine": "0.1.5",
"karma-chrome-launcher": "^0.1.4",
"karma-coverage": "~0.1.4",
"karma-firefox-launcher": "~0.1.3",
"karma-safari-launcher": "^0.1.1"
"jasmine-core": "^2.2.0",
"karma": "^0.12.31",
"karma-chrome-launcher": "^0.1.7",
"karma-firefox-launcher": "^0.1.4",
"karma-jasmine": "^0.3.5",
"karma-safari-launcher": "^0.1.1",
"karma-sauce-launcher": "^0.2.10",
"nodejs-websocket": "^1.2.0"
}
}
106 changes: 106 additions & 0 deletions test/counting-zone.disabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
'use strict';

describe('Zone.countingZone', function () {
function makeCountingZone() {
return zone.fork(Zone.longStackTraceZone).
fork(Zone.countingZone);
}

it('should flush at the end of a run', function (done) {
makeCountingZone().fork({
onFlush: done
}).run(function () { });
});


it('should work with setTimeout', function (done) {
var countingZone = makeCountingZone();
countingZone.run(function () {
setTimeout(function () {
expect(countingZone.counter()).toBe(0);
done();
}, 0);
expect(countingZone.counter()).toBe(1);
});
});


it('should work with clearTimeout', function (done) {
var countingZone = makeCountingZone();

makeCountingZone().run(function () {
var id = setTimeout(function () {}, 0);
expect(countingZone.counter()).toBe(1);
clearTimeout(id);
expect(countingZone.counter()).toBe(0);
done();
});
});


it('should work with setInterval', function (done) {
var latch = 0,
countingZone = makeCountingZone(),
id;

countingZone.run(function () {
expect(countingZone.counter()).toBe(0);

id = setInterval(function () {
latch += 1;

// setInterval should run multiple times
if (latch === 2) {
finish();
}
}, 0);

expect(countingZone.counter()).toBe(1);
});

function finish() {
expect(countingZone.counter()).toBe(1);
clearInterval(id);
done();
}
});


it('should work with clearInterval', function (done) {
var id;
countingZone.run(function () {
id = setInterval(function () {
latch += 1;
}, 0);
expect(countingZone.counter()).toBe(1);
clearInterval(id);
expect(countingZone.counter()).toBe(0);
done();
});
});


it('should work with addEventListener', function (done) {
var elt = document.createElement('button');
expect(countingZone.counter()).toBe(0);
countingZone.run(main);

function main () {
expect(countingZone.counter()).toBe(0);
elt.addEventListener('click', onClick);
expect(countingZone.counter()).toBe(1);

elt.click();
function onClick () {
expect(countingZone.counter()).toBe(1);
elt.removeEventListener('click', onClick);
expect(countingZone.counter()).toBe(0);

done();
clicked = true;
}

expect(countingZone.counter()).toBe(0);
}
});
});
123 changes: 0 additions & 123 deletions test/counting-zone.spec.js

This file was deleted.

22 changes: 11 additions & 11 deletions test/long-stack-trace-zone.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,39 @@ describe('longStackTraceZone', function () {

beforeEach(function () {
log = [];
jasmine.Clock.useMock();
});

it('should produce long stack traces', function () {
it('should produce long stack traces', function (done) {
lstz.run(function () {
setTimeout(function () {
setTimeout(function () {
setTimeout(function () {
expect(log[0]).toBe('Error: hello');
expect(log[1].split('--- ').length).toBe(4);
done();
}, 0);
throw new Error('hello');
}, 0);
}, 0);
});

jasmine.Clock.tick(0);

expect(log[0]).toBe('Error: hello');
expect(log[1].split('--- ').length).toBe(4);
});


it('should filter based on stackFramesFilter', function () {
it('should filter based on stackFramesFilter', function (done) {
lstz.fork({
stackFramesFilter: function (line) {
return line.indexOf('jasmine.js') === -1;
}
}).run(function () {
setTimeout(function () {
setTimeout(function () {
setTimeout(function () {
expect(log[1]).not.toContain('jasmine.js');
done();
}, 0);
throw new Error('hello');
}, 0);
}, 0);
});

jasmine.Clock.tick(0);
expect(log[1]).not.toContain('jasmine.js');
});
});
Loading

0 comments on commit 4a48f96

Please sign in to comment.