Skip to content

Instantly share code, notes, and snippets.

@tutuca
Created March 3, 2015 17:45
Show Gist options
  • Save tutuca/a46b94c91047d89c7891 to your computer and use it in GitHub Desktop.
Save tutuca/a46b94c91047d89c7891 to your computer and use it in GitHub Desktop.
Make fakeTimers work with an arbitrary date from moment.js
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