Mock date constructor with Jasmine
问题 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(); }); See: https://github.com/pivotal/jasmine/wiki/Spies 回答1: Credit