Created
July 22, 2015 11:49
-
-
Save jhartikainen/16c50769369c047a2fd3 to your computer and use it in GitHub Desktop.
sinon.spy wrapper for IE8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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