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

253
Views
Simule hacer clic en un elemento cuando use element.eventlistener en jest + configuración de enzimas

Tengo un componente, digamos <MyComponent> . Tengo un <button>Click me</button> en el componente que tiene un detector de eventos al hacer clic agregado en useEffect

 useEffect(() => { const btn = document.getElementById('button'); if (btn) { btn.addEventListener('click', onButtonClicked, false); } return function cleanupListener() { if (btn) btn.removeEventListener('click', onButtonClicked); }; }, []);

Necesito simular hacer clic en ese botón en el caso de prueba usando broma + enzima. Pasé por una de las respuestas que tenía una solución como esta, pero no funcionó.

 beforeEach(() => { const map = {}; const namedByRefComponent = Wrapper.find("button"); const namedByRefDomNode = namedByRefComponent.getDOMNode(); const namedByRefDomNode = ReactDOM.findDOMNode(namedByRefComponent); namedByRefDomNode.addEventListener = jest .fn() .mockImplementation((event, cb) => { map[event] = cb; }); });

¿Puede alguien ayudarme con una nueva solución o completar la solución anterior porque no puedo resolverlo?

Gracias por adelantado

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!