Created
February 15, 2018 22:39
-
-
Save cmstead/df89cf61498450b3ccef18d8befb8a25 to your computer and use it in GitHub Desktop.
Testing when using window
This file contains hidden or 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
describe('myTest', function () { | |
it('should interact with window', function () { | |
function AudioContext() { | |
this.foo = 'bar'; | |
} | |
AudioContext.prototype = { | |
doThatThingYouDo: sinon.spy() | |
}; | |
const windowFake = { | |
AudioContext: AudioContext | |
}; | |
buildApi(windowFake); | |
windowFake.exportedFunctions.callTheThing(); | |
assert.equal(AudioContext.prototype.doThatThingYouDo.callCount, 1); | |
}); | |
}); | |
function buildApi(window) { | |
function callTheThing() { | |
const audioContext = new window.AudioContext(); | |
audioContext.doThatThingYouDo(); | |
} | |
const exportedFunctions = { | |
callTheThing: callTheThing | |
} | |
window.exportedFunctions = exportedFunctions; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment