Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Cómo escribir una prueba unitaria para el código JS de formato AMD usando broma

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ó.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!