Skip to content

Instantly share code, notes, and snippets.

@adamyanalunas
Last active December 16, 2015 17:59
Show Gist options
  • Save adamyanalunas/5474221 to your computer and use it in GitHub Desktop.
Save adamyanalunas/5474221 to your computer and use it in GitHub Desktop.
Sinon's time freezing is destroyed by Sugar.js
exports.DateHelper = {
lock: (msSinceEpoc) ->
# NOTE: Needed because Calendar model expects moment in the global scope.
global.moment = require('moment')
# NOTE: This can be removed once Sugar.js is removed
dateSugar = Date.SugarMethods
clock = sinon.useFakeTimers(msSinceEpoc)
# NOTE: This can be removed once Sugar.js is removed
Date[k] = v.method for k,v of dateSugar
originalCreate = Date.create
@createStub = sinon.stub(Date, 'create', (dateString) -> if dateString then originalCreate(dateString) else new Date())
clock
unlock: (clock) ->
global.moment = null
clock.restore()
@createStub.restore()
}
QUnit.module 'Brilliant.Calendar'
setup: ->
@clock = DateHelper.lock(+new Date(2012, 9, 7))
@getEventsStub = sinon.stub(app.Calendar.prototype, 'getEvents')
teardown: ->
@getEventsStub.restore()
DateHelper.unlock(@clock)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment