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

228
Views
Probando un gancho personalizado con useSelector

Tengo un enlace personalizado que escribí y estoy tratando de probar solo el enlace en sí, pero necesito envolverlo dentro de un Proveedor. ver error a continuación

 Error: could not find react-redux context value; please ensure the component is wrapped in a <Provider>

A continuación se muestra mi gancho personalizado.

 import _ from 'lodash'; import { useSelector } from 'react-redux'; const useSelectedTable = () => { const { tables, currentTableId } = useSelector((state: any) => { return { tables: state.tables, currentTableId: state.currentTableId }; }); const table = _.find(tables, tab => tab._id === currentTableId); return table; }; export default useSelectedTable;

La prueba en la que estoy trabajando se ve así en este momento.

 describe('useSelectedTable', () => { test('Should get current selected table', () => { const { result } = renderHook(() => useSelectedTable()); console.log(result.all); }); });

¿Alguna idea?

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

0

Dado que el enlace usa redux, deberá agregar un contenedor que tenga la tienda, algo como esto:

 const store = {} // whatever you to do test your mock store today const wrapper = ({ children }) => <Provider store={store}>{children}</Provider> renderHook(() => useSelectedTable(), { wrapper });

aquí están los documentos que hablan sobre agregar el contenedor con ganchos de reacción https://react-hooks-testing-library.com/usage/advanced-hooks#context

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!