Deprecate non-Date arguments to jasmine.clock().mockDate()
This commit is contained in:
@@ -60,7 +60,7 @@ var getJasmineRequireObj = (function(jasmineGlobal) {
|
||||
j$.Any = jRequire.Any(j$);
|
||||
j$.Anything = jRequire.Anything(j$);
|
||||
j$.CallTracker = jRequire.CallTracker(j$);
|
||||
j$.MockDate = jRequire.MockDate();
|
||||
j$.MockDate = jRequire.MockDate(j$);
|
||||
j$.getClearStack = jRequire.clearStack(j$);
|
||||
j$.Clock = jRequire.Clock();
|
||||
j$.DelayedFunctionScheduler = jRequire.DelayedFunctionScheduler(j$);
|
||||
@@ -7774,7 +7774,7 @@ getJasmineRequireObj().toThrowMatching = function(j$) {
|
||||
return toThrowMatching;
|
||||
};
|
||||
|
||||
getJasmineRequireObj().MockDate = function() {
|
||||
getJasmineRequireObj().MockDate = function(j$) {
|
||||
function MockDate(global) {
|
||||
var self = this;
|
||||
var currentTime = 0;
|
||||
@@ -7792,6 +7792,14 @@ getJasmineRequireObj().MockDate = function() {
|
||||
if (mockDate instanceof GlobalDate) {
|
||||
currentTime = mockDate.getTime();
|
||||
} else {
|
||||
if (!j$.util.isUndefined(mockDate)) {
|
||||
j$.getEnv().deprecated(
|
||||
'The argument to jasmine.clock().mockDate(), if specified, ' +
|
||||
'should be a Date instance. Passing anything other than a Date ' +
|
||||
'will be treated as an error in a future release.'
|
||||
);
|
||||
}
|
||||
|
||||
currentTime = new GlobalDate().getTime();
|
||||
}
|
||||
|
||||
|
||||
@@ -950,6 +950,28 @@ describe('Clock (acceptance)', function() {
|
||||
expect(timeoutDate).toEqual(baseTime.getTime() + 150);
|
||||
});
|
||||
|
||||
it('logs a deprecation when mockDate is called with a non-Date', function() {
|
||||
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
global = { Date: Date },
|
||||
mockDate = new jasmineUnderTest.MockDate(global),
|
||||
clock = new jasmineUnderTest.Clock(
|
||||
{ setTimeout: setTimeout },
|
||||
function() {
|
||||
return delayedFunctionScheduler;
|
||||
},
|
||||
mockDate
|
||||
),
|
||||
env = jasmineUnderTest.getEnv();
|
||||
|
||||
spyOn(env, 'deprecated');
|
||||
clock.mockDate(12345);
|
||||
expect(env.deprecated).toHaveBeenCalledWith(
|
||||
'The argument to jasmine.clock().mockDate(), if specified, should be ' +
|
||||
'a Date instance. Passing anything other than a Date will be ' +
|
||||
'treated as an error in a future release.'
|
||||
);
|
||||
});
|
||||
|
||||
it('mocks the Date object and updates the date per delayed function', function() {
|
||||
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
global = { Date: Date },
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
getJasmineRequireObj().MockDate = function() {
|
||||
getJasmineRequireObj().MockDate = function(j$) {
|
||||
function MockDate(global) {
|
||||
var self = this;
|
||||
var currentTime = 0;
|
||||
@@ -16,6 +16,14 @@ getJasmineRequireObj().MockDate = function() {
|
||||
if (mockDate instanceof GlobalDate) {
|
||||
currentTime = mockDate.getTime();
|
||||
} else {
|
||||
if (!j$.util.isUndefined(mockDate)) {
|
||||
j$.getEnv().deprecated(
|
||||
'The argument to jasmine.clock().mockDate(), if specified, ' +
|
||||
'should be a Date instance. Passing anything other than a Date ' +
|
||||
'will be treated as an error in a future release.'
|
||||
);
|
||||
}
|
||||
|
||||
currentTime = new GlobalDate().getTime();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ var getJasmineRequireObj = (function(jasmineGlobal) {
|
||||
j$.Any = jRequire.Any(j$);
|
||||
j$.Anything = jRequire.Anything(j$);
|
||||
j$.CallTracker = jRequire.CallTracker(j$);
|
||||
j$.MockDate = jRequire.MockDate();
|
||||
j$.MockDate = jRequire.MockDate(j$);
|
||||
j$.getClearStack = jRequire.clearStack(j$);
|
||||
j$.Clock = jRequire.Clock();
|
||||
j$.DelayedFunctionScheduler = jRequire.DelayedFunctionScheduler(j$);
|
||||
|
||||
Reference in New Issue
Block a user