Use sinon's fake timers

This commit is contained in:
John Firebaugh
2013-01-18 15:00:50 -08:00
parent e19f86a285
commit 2b45a5b452
2 changed files with 15 additions and 6 deletions

View File

@@ -10,7 +10,7 @@ iD.ui.flash = function() {
modal.on('click.flash', function() { modal.remove(); });
d3.timer(function() {
setTimeout(function() {
modal.remove();
return true;
}, 1000);

View File

@@ -1,13 +1,22 @@
describe("iD.ui.flash", function () {
var clock;
beforeEach(function () {
clock = sinon.useFakeTimers();
});
afterEach(function () {
clock.restore();
});
it('can be instantiated', function () {
var flash = iD.ui.flash();
expect(flash).to.be.ok;
});
it('leaves after 1000 ms', function (done) {
it('leaves after 1000 ms', function () {
var flash = iD.ui.flash();
window.setTimeout(function() {
expect(flash.node().parentNode).to.be.null;
done();
}, 1200);
clock.tick(1010);
expect(flash.node().parentNode).to.be.null;
});
});