I'm testing a function that takes a date as an optional argument. I want to assert that a new Date object is created if the function is called without the argument.
var foo = function (date) {
var d = date || new Date();
return d.toISOString();
}
How do I assert that new Date
is called?
So far, I've got something like this:
it('formats today like ISO-8601', function () {
spyOn(Date, 'prototype');
expect().toHaveBeenCalled();
});
this worked for me
from jasmine example,
jasmine date
for me it worked with:
instead of
.andCallFake
(using "grunt-contrib-jasmine": "^0.6.5", that seems to include jasmine 2.0.0)For the users who are using Edge version of Jasmine:
Credit to @HMR. Test I wrote to verify: