javascript - Jasmine test for Knockoutjs -
how test (using jasmine) if pre defined function such compute or subscribe called when observable variables change in knockoutjs
for example:
self.report.subscribe(function(){ clearall(); });
if change value of report observable clearall function called subscribe function not executing expected
thanks in advance.
you can use spyon method. syntax:
spyon(myobject, 'nameofmethodtospyon'); //do stuff expect(moobject.nameofthemethodtospyon).tohavebeencalled();
example:
spyon(window, 'alert'); alert('hi'); expect(window.alert).tohavebeencalledwith('hi');
so like:
spyon(mymodel, 'clearall'); mymodel.report('something'); expect(mymodel.clearall).tohavebeencalled();
reference: http://jasmine.github.io/2.0/introduction.html#section-spies
you should test own code. subscribe function part of knockoutjs , doesn't need more testing.
Comments
Post a Comment