Last active
December 16, 2015 17:59
-
-
Save adamyanalunas/5474221 to your computer and use it in GitHub Desktop.
Sinon's time freezing is destroyed by Sugar.js
This file contains hidden or 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
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() | |
} |
This file contains hidden or 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
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