Merge branch 'fix-clock-date' of https://github.com/andrewiggins/jasmine into andrewiggins-fix-clock-date

Fixes #915
Merges #980
This commit is contained in:
Gregg Van Hove
2015-12-22 14:49:18 -08:00
4 changed files with 42 additions and 6 deletions

View File

@@ -652,4 +652,23 @@ describe("Clock (acceptance)", function() {
expect(timeoutDate).toEqual(baseTime.getTime() + 150);
});
it("mocks the Date object and updates the date per delayed function", function () {
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
global = {Date: Date},
mockDate = new jasmineUnderTest.MockDate(global),
clock = new jasmineUnderTest.Clock({setTimeout: setTimeout}, function () { return delayedFunctionScheduler; }, mockDate),
baseTime = new Date();
clock.install().mockDate(baseTime);
var actualTimes = [];
var pushCurrentTime = function() { actualTimes.push(global.Date().getTime()); };
delayedFunctionScheduler.scheduleFunction(pushCurrentTime);
delayedFunctionScheduler.scheduleFunction(pushCurrentTime, 1);
clock.tick(1);
expect(actualTimes).toEqual([baseTime.getTime(), baseTime.getTime() + 1]);
})
});

View File

@@ -251,5 +251,18 @@ describe("DelayedFunctionScheduler", function() {
expect(fn).toHaveBeenCalled();
expect(fn.calls.count()).toBe(1);
});
it("updates the mockDate per scheduled time", function () {
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
tickDate = jasmine.createSpy('tickDate');
scheduler.scheduleFunction(function() {});
scheduler.scheduleFunction(function() {}, 1);
scheduler.tick(1, tickDate);
expect(tickDate).toHaveBeenCalledWith(0);
expect(tickDate).toHaveBeenCalledWith(1);
})
});