Build distribution to include MockDate
- Forgot to do this when merging the pull request - Also fix quotes for string to match jshint rules
This commit is contained in:
@@ -36,6 +36,7 @@ getJasmineRequireObj().core = function(jRequire) {
|
|||||||
j$.util = jRequire.util();
|
j$.util = jRequire.util();
|
||||||
j$.Any = jRequire.Any();
|
j$.Any = jRequire.Any();
|
||||||
j$.CallTracker = jRequire.CallTracker();
|
j$.CallTracker = jRequire.CallTracker();
|
||||||
|
j$.MockDate = jRequire.MockDate();
|
||||||
j$.Clock = jRequire.Clock();
|
j$.Clock = jRequire.Clock();
|
||||||
j$.DelayedFunctionScheduler = jRequire.DelayedFunctionScheduler();
|
j$.DelayedFunctionScheduler = jRequire.DelayedFunctionScheduler();
|
||||||
j$.Env = jRequire.Env(j$);
|
j$.Env = jRequire.Env(j$);
|
||||||
@@ -363,7 +364,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
|
|
||||||
var realSetTimeout = j$.getGlobal().setTimeout;
|
var realSetTimeout = j$.getGlobal().setTimeout;
|
||||||
var realClearTimeout = j$.getGlobal().clearTimeout;
|
var realClearTimeout = j$.getGlobal().clearTimeout;
|
||||||
this.clock = new j$.Clock(global, new j$.DelayedFunctionScheduler());
|
this.clock = new j$.Clock(global, new j$.DelayedFunctionScheduler(), new j$.MockDate(global));
|
||||||
|
|
||||||
var runnableLookupTable = {};
|
var runnableLookupTable = {};
|
||||||
|
|
||||||
@@ -851,7 +852,7 @@ getJasmineRequireObj().CallTracker = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
getJasmineRequireObj().Clock = function() {
|
getJasmineRequireObj().Clock = function() {
|
||||||
function Clock(global, delayedFunctionScheduler) {
|
function Clock(global, delayedFunctionScheduler, mockDate) {
|
||||||
var self = this,
|
var self = this,
|
||||||
realTimingFunctions = {
|
realTimingFunctions = {
|
||||||
setTimeout: global.setTimeout,
|
setTimeout: global.setTimeout,
|
||||||
@@ -868,19 +869,28 @@ getJasmineRequireObj().Clock = function() {
|
|||||||
installed = false,
|
installed = false,
|
||||||
timer;
|
timer;
|
||||||
|
|
||||||
|
|
||||||
self.install = function() {
|
self.install = function() {
|
||||||
replace(global, fakeTimingFunctions);
|
replace(global, fakeTimingFunctions);
|
||||||
timer = fakeTimingFunctions;
|
timer = fakeTimingFunctions;
|
||||||
installed = true;
|
installed = true;
|
||||||
|
|
||||||
|
return self;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.uninstall = function() {
|
self.uninstall = function() {
|
||||||
delayedFunctionScheduler.reset();
|
delayedFunctionScheduler.reset();
|
||||||
|
mockDate.uninstall();
|
||||||
replace(global, realTimingFunctions);
|
replace(global, realTimingFunctions);
|
||||||
|
|
||||||
timer = realTimingFunctions;
|
timer = realTimingFunctions;
|
||||||
installed = false;
|
installed = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
self.mockDate = function(initialDate) {
|
||||||
|
mockDate.install(initialDate);
|
||||||
|
};
|
||||||
|
|
||||||
self.setTimeout = function(fn, delay, params) {
|
self.setTimeout = function(fn, delay, params) {
|
||||||
if (legacyIE()) {
|
if (legacyIE()) {
|
||||||
if (arguments.length > 2) {
|
if (arguments.length > 2) {
|
||||||
@@ -911,6 +921,7 @@ getJasmineRequireObj().Clock = function() {
|
|||||||
|
|
||||||
self.tick = function(millis) {
|
self.tick = function(millis) {
|
||||||
if (installed) {
|
if (installed) {
|
||||||
|
mockDate.tick(millis);
|
||||||
delayedFunctionScheduler.tick(millis);
|
delayedFunctionScheduler.tick(millis);
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Mock clock is not installed, use jasmine.clock().install()');
|
throw new Error('Mock clock is not installed, use jasmine.clock().install()');
|
||||||
@@ -1284,6 +1295,73 @@ getJasmineRequireObj().buildExpectationResult = function() {
|
|||||||
return buildExpectationResult;
|
return buildExpectationResult;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
getJasmineRequireObj().MockDate = function() {
|
||||||
|
function MockDate(global) {
|
||||||
|
var self = this;
|
||||||
|
var currentTime = 0;
|
||||||
|
|
||||||
|
if (!global || !global.Date) {
|
||||||
|
self.install = function() {};
|
||||||
|
self.tick = function() {};
|
||||||
|
self.uninstall = function() {};
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
var GlobalDate = global.Date;
|
||||||
|
|
||||||
|
self.install = function(mockDate) {
|
||||||
|
if (mockDate instanceof GlobalDate) {
|
||||||
|
currentTime = mockDate.getTime();
|
||||||
|
} else {
|
||||||
|
currentTime = new GlobalDate().getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
global.Date = FakeDate;
|
||||||
|
};
|
||||||
|
|
||||||
|
self.tick = function(millis) {
|
||||||
|
millis = millis || 0;
|
||||||
|
currentTime = currentTime + millis;
|
||||||
|
};
|
||||||
|
|
||||||
|
self.uninstall = function() {
|
||||||
|
currentTime = 0;
|
||||||
|
global.Date = GlobalDate;
|
||||||
|
};
|
||||||
|
|
||||||
|
createDateProperties();
|
||||||
|
|
||||||
|
return self;
|
||||||
|
|
||||||
|
function FakeDate() {
|
||||||
|
if (arguments.length === 0) {
|
||||||
|
return new GlobalDate(currentTime);
|
||||||
|
} else {
|
||||||
|
return new GlobalDate(arguments[0], arguments[1], arguments[2],
|
||||||
|
arguments[3], arguments[4], arguments[5], arguments[6]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createDateProperties() {
|
||||||
|
|
||||||
|
FakeDate.now = function() {
|
||||||
|
if (GlobalDate.now) {
|
||||||
|
return currentTime;
|
||||||
|
} else {
|
||||||
|
throw new Error('Browser does not support Date.now()');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
FakeDate.toSource = GlobalDate.toSource;
|
||||||
|
FakeDate.toString = GlobalDate.toString;
|
||||||
|
FakeDate.parse = GlobalDate.parse;
|
||||||
|
FakeDate.UTC = GlobalDate.UTC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return MockDate;
|
||||||
|
};
|
||||||
|
|
||||||
getJasmineRequireObj().ObjectContaining = function(j$) {
|
getJasmineRequireObj().ObjectContaining = function(j$) {
|
||||||
|
|
||||||
function ObjectContaining(sample) {
|
function ObjectContaining(sample) {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ getJasmineRequireObj().MockDate = function() {
|
|||||||
if (GlobalDate.now) {
|
if (GlobalDate.now) {
|
||||||
return currentTime;
|
return currentTime;
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Browser does not support Date.now()");
|
throw new Error('Browser does not support Date.now()');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user