Allow mocked Date constructor to be called with a subset of full params
Fix #643 #624
This commit is contained in:
@@ -1352,11 +1352,26 @@ getJasmineRequireObj().MockDate = function() {
|
|||||||
return self;
|
return self;
|
||||||
|
|
||||||
function FakeDate() {
|
function FakeDate() {
|
||||||
if (arguments.length === 0) {
|
switch(arguments.length) {
|
||||||
return new GlobalDate(currentTime);
|
case 0:
|
||||||
} else {
|
return new GlobalDate(currentTime);
|
||||||
return new GlobalDate(arguments[0], arguments[1], arguments[2],
|
case 1:
|
||||||
arguments[3], arguments[4], arguments[5], arguments[6]);
|
return new GlobalDate(arguments[0]);
|
||||||
|
case 2:
|
||||||
|
return new GlobalDate(arguments[0], arguments[1]);
|
||||||
|
case 3:
|
||||||
|
return new GlobalDate(arguments[0], arguments[1], arguments[2]);
|
||||||
|
case 4:
|
||||||
|
return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3]);
|
||||||
|
case 5:
|
||||||
|
return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3],
|
||||||
|
arguments[4]);
|
||||||
|
case 6:
|
||||||
|
return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3],
|
||||||
|
arguments[4], arguments[5]);
|
||||||
|
case 7:
|
||||||
|
return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3],
|
||||||
|
arguments[4], arguments[5], arguments[6]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -157,15 +157,35 @@ describe("FakeDate", function() {
|
|||||||
expect(fakeGlobal.Date.now()).toEqual(1000);
|
expect(fakeGlobal.Date.now()).toEqual(1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("allows to create a Date in a different time than the mocked time", function() {
|
it("allows creation of a Date in a different time than the mocked time", function() {
|
||||||
var fakeGlobal = { Date: Date },
|
var fakeGlobal = { Date: Date },
|
||||||
mockDate = new j$.MockDate(fakeGlobal),
|
mockDate = new j$.MockDate(fakeGlobal);
|
||||||
baseDate = new Date(2013, 9, 23, 0, 0, 0, 0);
|
|
||||||
|
|
||||||
mockDate.install(baseDate);
|
mockDate.install();
|
||||||
|
|
||||||
var otherDate = new fakeGlobal.Date(2013, 9, 23, 0, 0, 1, 0);
|
var otherDate = new fakeGlobal.Date(2013, 9, 23, 0, 0, 1, 0);
|
||||||
expect(otherDate.getTime()).not.toEqual(baseDate.getTime());
|
expect(otherDate.getTime()).toEqual(new Date(2013, 9, 23, 0, 0, 1, 0).getTime());
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allows creation of a Date that isn't fully specified", function() {
|
||||||
|
var fakeGlobal = { Date: Date },
|
||||||
|
mockDate = new j$.MockDate(fakeGlobal);
|
||||||
|
|
||||||
|
mockDate.install();
|
||||||
|
|
||||||
|
var otherDate = new fakeGlobal.Date(2013, 9, 23);
|
||||||
|
expect(otherDate.getTime()).toEqual(new Date(2013, 9, 23).getTime());
|
||||||
|
});
|
||||||
|
|
||||||
|
it('allows creation of a Date with millis', function() {
|
||||||
|
var fakeGlobal = { Date: Date },
|
||||||
|
mockDate = new j$.MockDate(fakeGlobal),
|
||||||
|
now = new Date(2014, 3, 15).getTime();
|
||||||
|
|
||||||
|
mockDate.install();
|
||||||
|
|
||||||
|
var otherDate = new fakeGlobal.Date(now);
|
||||||
|
expect(otherDate.getTime()).toEqual(now);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("copies all Date properties to the mocked date", function() {
|
it("copies all Date properties to the mocked date", function() {
|
||||||
|
|||||||
@@ -37,11 +37,26 @@ getJasmineRequireObj().MockDate = function() {
|
|||||||
return self;
|
return self;
|
||||||
|
|
||||||
function FakeDate() {
|
function FakeDate() {
|
||||||
if (arguments.length === 0) {
|
switch(arguments.length) {
|
||||||
return new GlobalDate(currentTime);
|
case 0:
|
||||||
} else {
|
return new GlobalDate(currentTime);
|
||||||
return new GlobalDate(arguments[0], arguments[1], arguments[2],
|
case 1:
|
||||||
arguments[3], arguments[4], arguments[5], arguments[6]);
|
return new GlobalDate(arguments[0]);
|
||||||
|
case 2:
|
||||||
|
return new GlobalDate(arguments[0], arguments[1]);
|
||||||
|
case 3:
|
||||||
|
return new GlobalDate(arguments[0], arguments[1], arguments[2]);
|
||||||
|
case 4:
|
||||||
|
return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3]);
|
||||||
|
case 5:
|
||||||
|
return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3],
|
||||||
|
arguments[4]);
|
||||||
|
case 6:
|
||||||
|
return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3],
|
||||||
|
arguments[4], arguments[5]);
|
||||||
|
case 7:
|
||||||
|
return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3],
|
||||||
|
arguments[4], arguments[5], arguments[6]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user