Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
sinon.spy wrapper for IE8
* Spy on an object in a way that IE8 likes it
* If trying to use sinon.spy(document, 'createElement') or such in IE8,
* it will not work correctly. This function wraps the call in a way
* that it's supported in IE.
* May have possible side-effects to more specialized asserts,, but
* at least calledWith, return values, etc. * work correctly.
* @param {object} obj
* @param {string} method
* @return {spy}
function spyOn(obj, method) {
var actual = obj[method];
var spy = sinon.spy(function() { return actual.apply(obj, arguments); });
spy.restore = function() {
obj[method] = actual;
obj[method] = spy;
return spy;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment