--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To post to this group, send email to jasmi...@googlegroups.com.
To unsubscribe from this group, send email to jasmine-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jasmine-js?hl=en.
spyOn(Date, "getTime").andReturn(0);
... load your code/apply your behavior, etc ...
Date.getTime.andReturn(2);
$('someLink').click();
expect(duration).toEqual(2);
it's also possible to use a fake to do this, but it this case it might
be overkill:
var spyCount = 0;
spyOn(Date, "getTime").andCallFake(function() {
spyCount++;
return spyCount;
});
... load your code/apply your behavior, etc ...
$('someLink').click();
expect(duration).toEqual(1);
Sorry, this was from memory. getTime requires a date instance, because
it's going to provide you with the timestamp from that particular date
object. When you don't pass in anything to Date() it uses the current
time, which is why new Date().getTime() is giving you the current
timestamp. You've got a couple options here. Use Date.now() to get
the current time and spyOn(Date, 'now') (not sure what the
cross-browser is like on Date.now).
Another way to approach it if you still want to use Date().getTime()
is to wrap it with your own class, ie:
function MyDate() {
};
MyDate.currentTime = function() {
return Date().getTime();
}
Then you can spyOn(MyDate, "getTime");
Thanks
Rajan