Skip to content

Instantly share code, notes, and snippets.

@Raynos Raynos/test.js Secret
Last active Dec 10, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.