Skip to content

Instantly share code, notes, and snippets.

@felixzapata
Created January 24, 2015 01:04
Show Gist options
  • Save felixzapata/1f640a182c8f5e24ff33 to your computer and use it in GitHub Desktop.
Save felixzapata/1f640a182c8f5e24ff33 to your computer and use it in GitHub Desktop.
Freeze / Stub Time in Jasmine tests
// http://grosser.it/2012/03/23/freeze-stub-time-in-jasmine-tests/
withTimeFrozenAt("2012-01-01", function(){
it("is frozen", function(){
// do something useful with time
})
})
var withTimeFrozenAt = function(time, fn){
describe('with time frozen at ' + time, function() {
var oldDate = Date;
beforeEach( function() {
Date = function() {
return new oldDate(time);
};
});
afterEach(function() {
Date = oldDate;
});
fn();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment