angularjs - jasmine spyOn on javascript new Date -
i unit testing client code in angulajs , understand code means
var newdate = new date(2013,6,29); spyon(date.prototype, 'gettime').and.callfake(function() { return newdate; });
we mockout gettime() methode of date object. want mock out new date() instead. example code want test contains line
payload.created_at = new date();
i dont have access payload.created_at. want tell jasmine whenever see new date(), replace given date give you. thinking of doesnt work.
spyon(date.prototype, 'new date').and.callfake(function() { return newdate; });
but new date not method of date. please can me figure out? thanks
the jasmine clock api allows fake out javascript date functionality without manually writing spy it.
in particular, read section mocking date.
Comments
Post a Comment