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

424
Views
¿Cómo escribir una prueba de unidad Jasmine para addEventListener?

No pude entender cómo podría escribir una prueba de unidad Jasmine para AddEventListener. ¿Cómo pruebo el siguiente código si addEventListener está funcionando?

 private static disableScrollingOnPageWhenPanelOpen(): void { window.addEventListener('DOMMouseScroll', PhoneInputComponent.preventDefault, { passive: false }); window.addEventListener('mousewheel', PhoneInputComponent.preventDefault, { passive: false }); window.addEventListener('touchmove', PhoneInputComponent.preventDefault, { passive: false });}

Esto es lo que he intentado pero no estaba funcionando.

 describe('disableScrollingOnPageWhenPanelOpen', () => { it('should disable DOMMouseScroll', () => { const e = new Event('DOMMouseScroll'); PhoneInputComponent['disableScrollingOnPageWhenPanelOpen'](); window.dispatchEvent(e); spyOn(window, 'addEventListener').and.callThrough(); expect(window).toHaveBeenCalledWith('e', PhoneInputComponent['preventDefault'], { passive: false }); });

¿Podría alguien ayudarme con esto? Iba a probar si se ha llamado a addEventListener, pero no estoy seguro de si el método que estoy usando es el enfoque correcto para probar el código.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

expect(window) , esta window de línea no es un espía.

Intenta cambiar la línea a:

 expect(window.addEventListener).not.toHaveBeenCalledWith('e', PhoneInputComponent['preventDefault'], { passive: false });
about 4 years ago · Juan Pablo Isaza Report
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!