Sinon – Checking if a function has been stubbed

Just a quick post here, in reference to using Sinon.jS, and checking whether or not a function has been stubbed.

Let’s say that you might have stubbed a function like this;

var foo = sinon.stub(jQuery, "ajax");

You can check to see if it’s been stubbed already, with this;

if ( jQuery.ajax.displayName === "ajax" ) { ... }