javascript - How to spy on jQuery's append function Sinon -
i trying use sinon.js
create spy on jquery.append
function.
i tried: var spy = sinon.spy($, "append");
, got following error: typeerror: attempted wrap undefined property append function
.
i amended to: var spy = sinon.spy($.fn, "append");
seems better, spy.called
false.
sinon.spy(object, "method")
expects object first parameter, $
function. should spy on $.prototype
this:
var spy = sinon.spy($.prototype, "append");
fiddle: http://jsfiddle.net/rz825/
or can spy single object this:
var spy = sinon.spy($("body"), "append");
fiddle: http://jsfiddle.net/g5j8h/
Comments
Post a Comment