-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the history unit test date independent by adding a date object m…
…ock.
- Loading branch information
Showing
3 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Date mock object that works as if current time is fixed at | ||
* Sun Oct 26 2014 23:12:54 GMT+0100 (CET) | ||
*/ | ||
|
||
'use strict'; | ||
|
||
define([], function() { | ||
|
||
var realDate; | ||
function mockDate(val) { | ||
if (!val) { | ||
this.date = new realDate(1414361574805); | ||
} else { | ||
this.date = new realDate(val); | ||
} | ||
} | ||
mockDate.hook = function() { | ||
if (realDate) { | ||
throw Error('Hook date called two times!'); | ||
} | ||
realDate = window.Date; | ||
window.Date = mockDate; | ||
} | ||
mockDate.restore = function() { | ||
window.Date = realDate; | ||
realDate = undefined; | ||
} | ||
mockDate.prototype.setDate = function(val) { | ||
return this.date.setDate(val); | ||
} | ||
mockDate.prototype.toLocaleDateString = function() { | ||
return this.date.toLocaleDateString(); | ||
} | ||
mockDate.prototype.valueOf = function() { | ||
return this.date.valueOf(); | ||
} | ||
mockDate.prototype.getDate = function() { | ||
return this.date.getDate(); | ||
} | ||
mockDate.prototype.getDay = function() { | ||
return this.date.getDay(); | ||
} | ||
mockDate.prototype.getMonth = function() { | ||
return this.date.getMonth(); | ||
} | ||
mockDate.prototype.getFullYear = function() { | ||
return this.date.getFullYear(); | ||
} | ||
mockDate.prototype.getHours = function() { | ||
return this.date.getHours(); | ||
} | ||
mockDate.prototype.getMinutes = function() { | ||
return this.date.getMinutes(); | ||
} | ||
mockDate.prototype.getTime = function() { | ||
return this.date.getTime(); | ||
} | ||
|
||
return mockDate; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters