-
-
Save Raynos/1a7f21fe4c38dd615ba8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var test = require("tape") | |
, mock = require("../utils/mock") | |
, EventEmitter = require("events").EventEmitter | |
, timer = require("../../public/timer") | |
function createTimer(mocks) { | |
return mock("../../public/timer" | |
, mocks || {}) | |
} | |
function noop() {} | |
test("timer emits seconds", function (t) { | |
var now = new Date() | |
, callCount = 0 | |
, Timer = createTimer({ | |
xhr: function (options, callback) { | |
process.nextTick(function () { | |
callback(null, now.toISOString()) | |
}) | |
} | |
, timers: { | |
setTimeout: function (callback, time) { | |
if (++callCount >= 3) { | |
return | |
} | |
t.equal(time, 1000) | |
process.nextTick(callback) | |
} | |
} | |
}) | |
now.setHours(0) | |
var timer = Timer() | |
timer.once("second", function (time) { | |
t.equal(now.valueOf() + 1000, time, "time is not as expected") | |
timer.once("second", function (time) { | |
t.equal(now.valueOf() + 2000, time, "time did not increase") | |
t.end() | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment