Skip to content

Instantly share code, notes, and snippets.

@jhartikainen
Created July 22, 2015 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhartikainen/16c50769369c047a2fd3 to your computer and use it in GitHub Desktop.
Save jhartikainen/16c50769369c047a2fd3 to your computer and use it in GitHub Desktop.
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