Estoy tratando de escribir una prueba unitaria para un reproductor de audio escrito en formato AMD JS. Pude simular define() siguiendo una solución provista aquí Pero recibo un error para el siguiente fragmento de código
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 } }); El error: ReferenceError: HTMLMediaElement is not defined
Traté de burlarme de HTMLMediaElement a través jest.spyOn como se muestra a continuación:
let playing; beforeEach(() => { playing = jest.spyOn(window.HTMLMediaElement.prototype, 'playing'). mockImplementation(() => {}); }); ¿Hay alguna manera de eliminar el error o simular el elemento HTMLMediaElement ?
También intenté cambiar la propiedad testEnvironment en la configuración de jest de node a jsdom pero eso no ayudó.