Merge branch 'mock-date' of https://github.com/jalopez/jasmine into jalopez-mock-date

This commit is contained in:
Elana Koren and Gregg Van Hove
2014-02-27 10:03:35 -08:00
6 changed files with 286 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
getJasmineRequireObj().Clock = function() {
function Clock(global, delayedFunctionScheduler) {
function Clock(global, delayedFunctionScheduler, date) {
var self = this,
realTimingFunctions = {
setTimeout: global.setTimeout,
@@ -16,15 +16,24 @@ getJasmineRequireObj().Clock = function() {
installed = false,
timer;
self.install = function() {
self.install = function(mockDate) {
replace(global, fakeTimingFunctions);
timer = fakeTimingFunctions;
installed = true;
if (date && mockDate) {
date.install(mockDate);
}
};
self.uninstall = function() {
delayedFunctionScheduler.reset();
if (date) {
date.uninstall();
}
replace(global, realTimingFunctions);
timer = realTimingFunctions;
installed = false;
};
@@ -59,6 +68,9 @@ getJasmineRequireObj().Clock = function() {
self.tick = function(millis) {
if (installed) {
if (date) {
date.tick(millis);
}
delayedFunctionScheduler.tick(millis);
} else {
throw new Error('Mock clock is not installed, use jasmine.clock().install()');