Support browsers that don't supply a Date.now()

- install the mockDate by calling `mockDate` on `clock` instead of
  passing an argument to `clock.install()`

[Finishes #66606132] Closes #361
This commit is contained in:
Elana Koren and Gregg Van Hove
2014-02-27 11:55:25 -08:00
parent 627a262085
commit eebba2ecca
4 changed files with 158 additions and 99 deletions

View File

@@ -1,5 +1,5 @@
getJasmineRequireObj().Clock = function() {
function Clock(global, delayedFunctionScheduler, date) {
function Clock(global, delayedFunctionScheduler, mockDate) {
var self = this,
realTimingFunctions = {
setTimeout: global.setTimeout,
@@ -17,27 +17,27 @@ getJasmineRequireObj().Clock = function() {
timer;
self.install = function(mockDate) {
self.install = function() {
replace(global, fakeTimingFunctions);
timer = fakeTimingFunctions;
installed = true;
if (date && mockDate) {
date.install(mockDate);
}
return self;
};
self.uninstall = function() {
delayedFunctionScheduler.reset();
if (date) {
date.uninstall();
}
mockDate.uninstall();
replace(global, realTimingFunctions);
timer = realTimingFunctions;
installed = false;
};
self.mockDate = function(initialDate) {
mockDate.install(initialDate);
};
self.setTimeout = function(fn, delay, params) {
if (legacyIE()) {
if (arguments.length > 2) {
@@ -68,9 +68,7 @@ getJasmineRequireObj().Clock = function() {
self.tick = function(millis) {
if (installed) {
if (date) {
date.tick(millis);
}
mockDate.tick(millis);
delayedFunctionScheduler.tick(millis);
} else {
throw new Error('Mock clock is not installed, use jasmine.clock().install()');