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

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -