Javascript Jasmine Testing: Prevent tested function to call function from object that was created within tested function -
i want test javascript function jasmine has structure this:
showedituser: function (...) { // more code here... var edituserview = new edituserview(); // more code here... edituserview.generate(...); }
edituserview.generate()
causes error. not matter because don't want test it. how can prevent being called?
edituserview
requirejs module extends module called baseview
. function generate()
defined in baseview
. there other modules extend baseview
, want of them not call generate while testing. how can jasmine? seems not possible spyon(...).and.callfake()
because don't have edituserview
object when calling function. there kind of static way tell jasmine callfake()
function generate
in baseview
?
there no "nice" way solve jasmine. think, take baseview viewobj
parameter nicer coding style. reduce dependencies of method. don't have know specific baseview
-class, need viewobj
has generate
-method.
showedituser: function(..., viewobj) { // ... viewobj.generate(...); }
then create viewmock , put function this:
var viewmock = {}; viewmock.generate = jasmine.createspy('generate() spy');
then call way:
showedituser(..., viewmock);
edit: here similar question
Comments
Post a Comment