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

148
Views
Reaccione a la representación condicional de la prueba usando el enlace useState basado en la respuesta de la API

Tengo este componente React que tiene un bloque que se procesa en función de una respuesta API.

 const SomeComponent = () => { const [render, setRender] = useState(false) const handleClick = async () => { const someFunction = await callToAPI() if (someFunction) { setRender(true) } } return ( <main> <button onClick={handleClick}></button> <ShouldRender when={render} data-test-id='should-render'> Something </ShouldRender> </main> ) }

Mientras escribo la prueba, no sé cómo probar esta representación condicional. Me gustaría saber si hay alguna manera de usar algo como fireEvent para establecer este estado en mi archivo SomeComponent.test.js .

Hasta ahora la prueba se ve así:

 test('renders component when button is clicked', () => { render(<SomeComponent />) const button = screen.queryByRole('button') fireEvent.click(button) const conditionalComponent = screen.getByTestId('should-render') expect(conditionalComponent).toBeInTheDocument() })
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!