Deprecate non-Date arguments to jasmine.clock().mockDate()

This commit is contained in:
Steve Gravrock
2021-09-23 16:04:39 -07:00
parent 497a7fc3e5
commit 64d58ed1f0
4 changed files with 42 additions and 4 deletions

View File

@@ -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 },