I am trying to write unit test for an audioPlayer written in AMD JS format.
I was able to mock define() following a solution provided here
But I am getting error for the following code snippet
Object.defineProperty(HTMLMediaElement.prototype, "playing", {
get: function() {
return !!(
this.currentTime > 0 && // audio at time 0 is not playing
!this.paused && // audio that is paused is not playing
!this.ended && // audio that is ended is not playing
this.readyState > 2); // audio that is not ready enough to play cannot be played
}
});
The error : ReferenceError: HTMLMediaElement is not defined
I tried to mock HTMLMediaElement via jest.spyOn like below:
let playing;
beforeEach(() => {
playing = jest.spyOn(window.HTMLMediaElement.prototype, 'playing').
mockImplementation(() => {});
});
Is there a way to remove the error or mock the HTMLMediaElement element.
I also tried changing the testEnvironment property in the jest config from node to jsdom but that did not help.