Skip to content

Instantly share code, notes, and snippets.

@Raynos

Raynos/test.js Secret

Last active December 10, 2015 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raynos/1a7f21fe4c38dd615ba8 to your computer and use it in GitHub Desktop.
Save Raynos/1a7f21fe4c38dd615ba8 to your computer and use it in GitHub Desktop.
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