3 <script src=
"../../resources/js-test.js"></script>
5 description('Test shouldBeNow() in js-test.js');
7 shouldBeNow("Date.now()");
8 shouldBeNow("new Date()");
10 debug("Testing type checking with a string. This should fail.");
11 shouldBeNow("'Hello world!'");
13 function stubDateNow(stubValue
, callback
)
15 var realDateNow
= Date
.now
;
16 Date
.now = function() { return stubValue
; }
20 Date
.now
= realDateNow
;
24 debug("Testing past dates. This should fail.");
25 stubDateNow(60000, function() {
29 debug("Testing future dates. This should fail.");
30 stubDateNow(60000, function() {
34 debug("Testing a slightly past date with the implicit delta. This should pass.");
35 stubDateNow(60000, function() {
39 debug("Testing a slightly future date with the implicit delta. This should pass.");
40 stubDateNow(60000, function() {
44 debug("Testing a past date with a large delta. This should pass.");
45 stubDateNow(60000, function() {
46 shouldBeNow("50000", 10000);
49 debug("Testing a future date with a large delta. This should pass.");
50 stubDateNow(60000, function() {
51 shouldBeNow("70000", 10000);
54 debug("Simulating a defective clock that always goes backwards. The test below should fail.");
55 var badClock
= Date
.now();
56 var realDateNow
= Date
.now
;
57 Date
.now = function() { return --badClock
; }
58 shouldBeNow("new Date()");
59 Date
.now
= realDateNow
;