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

174
Views
¿Cómo usar Jest para verificar si se procesa el contenido cargado asíncrono?

Tengo un componente que muestra una lista de datos, dada por un gancho. Mi gancho devuelve algunos datos sobre el montaje del componente, por lo que el componente siempre tiene algunos elementos para representar.

Componente MiLista:

 function MyList() { let {data} = useLoadData() return ( <ul> {data.map(i => <li key={i}>{i}</li>)} </ul> ) }

Gancho del cargador de datos:

 function useLoadData() { const [data, setData] = useState([]) const fetchData = useCallback((params) => { fetch("url") .then(res => res.json()) .then(res => setData(res)) }, []) useEffect(() => { fetchData() }, []) return {data, fetchData} }

Mi prueba es algo como esto pero no pasa. MiLista.prueba.js

 test('check if list contains item1', async () => { await act(async () => { render(<MyList/>) }); await waitFor(() => { // I'd look for a real text here that is renderer when the data loads expect(screen.getByText('item1')).toBeInTheDocument(); }) const item1 = screen.getByText("item1"); expect(item1).toBeInTheDocument() });

Quiero usar jest para verificar si los datos iniciales se procesaron o no, ¿hay alguna forma de hacerlo?

Yo uso ReactTestingLibrary.

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

0

hacer una prueba de broma asíncrona para realizar la prueba

 it("it should test", async () => { const wrapper = mount(<Component />) await new Promise(function (res) { setTimeout(()=> res("done"),4000) }) expect(wrapper)... });
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!