Created
March 3, 2015 17:45
-
-
Save tutuca/a46b94c91047d89c7891 to your computer and use it in GitHub Desktop.
Make fakeTimers work with an arbitrary date from moment.js
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
describe("Test sinon.fakeTimes with Moment.js", function() { | |
var today, tomorrow, ticks, clock; | |
beforeEach(function(){ | |
// get milliseconds since UNIX epoch for this date. | |
ticks = parseInt(moment('01/15/2015').format('x')); | |
// set the timers to start at expected time. | |
clock = sinon.useFakeTimers(ticks); | |
}); | |
afterEach(function(){ | |
clock.restore(); | |
}); | |
it("date is set in some arbitrary time.", function() { | |
today = new moment(); | |
tomorrow = today.add(1, 'days'); | |
expect(tomorrow.format('MM/DD/YYYY')).toBe('01/16/2015'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment