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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -