From b5775aec4f4435ffbbfe9bd50e4b2c1e4d1bc57f Mon Sep 17 00:00:00 2001 From: tcorral Date: Fri, 24 Jan 2014 02:02:23 +0100 Subject: [PATCH] Allow stub or spy Date object safely using a closure to get a clean copy [closes #506] --- lib/jasmine-core/jasmine.js | 8 ++++++-- src/core/Timer.js | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index a5614f9d..3460c7c9 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1721,11 +1721,15 @@ if (typeof window == void 0 && typeof exports == "object") { } getJasmineRequireObj().Timer = function() { + var defaultNow = (function(Date) { + return function() { return new Date().getTime(); }; + })(Date); + function Timer(options) { options = options || {}; - var now = options.now || function() { return new Date().getTime(); }, - startTime; + var now = options.now || defaultNow, + startTime; this.start = function() { startTime = now(); diff --git a/src/core/Timer.js b/src/core/Timer.js index 92cc97b1..f8270f41 100644 --- a/src/core/Timer.js +++ b/src/core/Timer.js @@ -1,9 +1,13 @@ getJasmineRequireObj().Timer = function() { + var defaultNow = (function(Date) { + return function() { return new Date().getTime(); }; + })(Date); + function Timer(options) { options = options || {}; - var now = options.now || function() { return new Date().getTime(); }, - startTime; + var now = options.now || defaultNow, + startTime; this.start = function() { startTime = now();