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

99
Views
Haga clic en el evento que no se dispara en JSDOM

Tengo una pequeña aplicación creada en Vanilla JavaScript. Para probar la aplicación, estoy usando Jest y JSDOM . Tengo un botón en la aplicación que elimina una tabla en fila. La prueba se parece a:

 it('Table deletes corresponding row when Delete is clicked', () => { const tableCells = document.querySelectorAll('table tbody tr td'); expect(tableCells[1].innerHTML).toBe('Some value'); const firstRowDeleteButton = document.querySelectorAll('table tbody tr button')[1]; firstRowDeleteButton.click(); expect(tableCells[1].innerHTML).toBe('Another value'); // row value should change after original row is deleted. });

La prueba anterior falla ya que Jest también recibe el mismo 'Algún valor' al final de la prueba. Por lo tanto, el botón Eliminar no hace clic (tenga la seguridad de que la funcionalidad de eliminación funciona bien, ya que la probé en la aplicación real). Incluso intenté simular un evento de clic como este:

 const evt = document.createEvent("HTMLEvents"); evt.initEvent("input", false, true); element.dispatchEvent(evt);

Pero esto tampoco funcionó. Entonces, ¿cómo puedo activar el evento de clic en JSDOM?

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

0

Sí, esa es una limitación de JSDOM, debe usar algo como https://testing-library.com/docs/ecosystem-user-event

 ... userEvent.click(firstRowDeleteButton) ...

NOTA: los ejemplos en esta página incluyen React pero user-event funciona bien aparte

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!