I'm writing a React app in which I use AudioContext
. Sometimes on certain versions of Safari, calling new
with AudioContext
(or window.AudioContext || window.webkitAudioContext;
) returns null
.
I've written code that guards against this. I was wondering if there is a way to imitate this behaviour? I would like to create a unit test in which I mock window.AudioContext
to be a class that when called with new
returns null
.
How can you achieve something so that:
const context = new FakeAudioContext();
sets context
to null
?