Skip to content

Instantly share code, notes, and snippets.

@cmstead
Created February 15, 2018 22:39
Show Gist options
  • Save cmstead/df89cf61498450b3ccef18d8befb8a25 to your computer and use it in GitHub Desktop.
Save cmstead/df89cf61498450b3ccef18d8befb8a25 to your computer and use it in GitHub Desktop.
Testing when using window
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