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

406
Views
Pase ref como contexto en react-testing-library con broma

Estoy probando suerte con las pruebas unitarias y aquí es donde estoy atascado. Las referencias para las entradas se guardan en un contexto global y estoy tratando de simular el contexto para poder probar los componentes correctamente.

El problema es que una vez que mis componentes llaman a la propiedad focus() de la referencia y no estoy seguro de cómo simular la referencia correctamente para que incluso mi prueba pueda usar la propiedad focus() .

Este es mi código de prueba:

 import { render as rtlRender, screen } from "@testing-library/react"; import "@testing-library/jest-dom"; import { Provider } from "react-redux"; import store from "../redux/store"; import { GlobalContextProvider } from "../common/GlobalContext"; import { SalesContextProvider } from "../Sales/SalesContext"; import PatientAutocomplete from "../Sales/PatientAutocomplete"; const dummySalesContext = { patientRef: null, }; const dummyGlobalContext = { currentComponent: "demo", setEnableGlobalNavigation: jest.fn(), }; const render = (component) => rtlRender(<Provider store={store()}>{component}</Provider>); test("renders learn react link", () => { render( <GlobalContextProvider value={dummyGlobalContext}> <SalesContextProvider value={dummySalesContext}> <PatientAutocomplete searchTerm="Demo" patientSelected={null} close={null} /> </SalesContextProvider> </GlobalContextProvider> ); const linkElement = screen.getByText(/Add patient/i); expect(linkElement).toBeInTheDocument(); });

Este es el error que se arroja: TypeError: no se puede leer la propiedad 'foco' de undefined

 }, [searchTerm, debounceFetchPatients]); useEffect(() => { if (!showEditPatient) patientRef.current.focus({ preventScroll: true }); ^ }, [showEditPatient]);
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!