Support browsers that don't supply a Date.now()

- install the mockDate by calling `mockDate` on `clock` instead of
  passing an argument to `clock.install()`

[Finishes #66606132] Closes #361
This commit is contained in:
Elana Koren and Gregg Van Hove
2014-02-27 11:55:25 -08:00
parent 627a262085
commit eebba2ecca
4 changed files with 158 additions and 99 deletions

View File

@@ -13,10 +13,10 @@ getJasmineRequireObj().MockDate = function() {
var GlobalDate = global.Date;
self.install = function(mockDate) {
if (mockDate instanceof Date) {
if (mockDate instanceof GlobalDate) {
currentTime = mockDate.getTime();
} else {
currentTime = GlobalDate.now();
currentTime = new GlobalDate().getTime();
}
global.Date = FakeDate;
@@ -48,7 +48,11 @@ getJasmineRequireObj().MockDate = function() {
function createDateProperties() {
FakeDate.now = function() {
return currentTime;
if (GlobalDate.now) {
return currentTime;
} else {
throw new Error("Browser does not support Date.now()");
}
};
FakeDate.toSource = GlobalDate.toSource;