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

105
Views
¿Es posible probar solo una función del componente con Jest?

Tengo un componente de reacción, por ejemplo, algo como esto:

 const MyComponent = (props) => { const [state, setState] = useState(true); const {data} = useContext(myContext); const location = useLocation(); //A lot of code here const myFunction = () => { return { dataFromContext: data, locationFromUseLocation: location, state: state } } return <>A lot of other components here</> }

Y estoy tratando de escribir una prueba que debería verse así:

 describe('Component test', () => { it('myFunction test', () => { const wrapper = shallow(<MyComponent/>); const expectedResult = { dataFromContext: 'any data here', locationFromUseLocation: 'any location here', state: false }; expect(wrapper.dive().instance().myFunction()).toEqual(expectedResult); }) })

¿Puedo useState , useContext y useLocation desde <MyComponent/> y pasar mis datos personalizados en lugar de datos reales del componente real?

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

0

Después de una investigación más profunda, entendí que en tal situación no puedo escribir una prueba solo para la función en mi componente. Entonces, he creado una prueba unitaria, que prueba todos mis componentes, no solo una función.

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!