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

242
Views
Cómo probar funciones internas definidas en componentes sin estado en React with Enzyme

Estoy usando enzimas para probar mis componentes de reacción. Tengo un componente sin estado que tiene una función interna. ¿Cómo puedo llamar y probar esa función interna?

Aquí está mi componente:

 const Btn = (props) => { const types = ['link', 'plainLink', 'primary', 'secondary', 'danger', 'info']; const handleClick = (event) => { event.preventDefault(); props.onClick(event); }; return ( <button onClick={handleClick} className={classes}> <span>{props.children}</span> </button> ); };

Intenté lo siguiente, pero aparece un error que dice: TypeError: undefined no es un constructor

 const btnComp = shallow(<Btn />); btnComp.instance().handleClick();
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Por lo general, pruebo esta funcionalidad configurando un sinon.spy para el evento:

 const click = sinon.spy(); const btnComp = shallow(<Btn onClick={click} />); btnComp.find('button').simulate('click'); expect(click.called).to.equal(true);

Ahora, sabe que la función interna sí invocó el evento props.onClick , que es la parte más importante de su trabajo.

over 4 years ago · Santiago Trujillo 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!