Created
January 24, 2015 01:04
-
-
Save felixzapata/1f640a182c8f5e24ff33 to your computer and use it in GitHub Desktop.
Freeze / Stub Time in Jasmine tests
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
// 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