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

138
Views
Cómo probar la función que devuelve un objeto con funciones dentro

tengo esta funcion:

 export const setData = (a, b) => (b !== undefined ? { a, b } : { a }); export const processData = arr => { const obj = {}; arr.forEach(item => obj[item[0]] = val => setData(item[1], val); return obj; };

La forma en que uso esta función es así:

 const data = [ ['setSomething', 'SET_SOMETHING'], ['setAnotherThing', 'SET_ANOTHER_THING'] ]; const setters = processData(data);

y luego puedo llamarlos como setters.setSomething() o setters.setSomething(1234) .

¿Cómo puedo probar esto con Jest? Pensé en esto:

 const mocked = [ ['setSomething', 'SET_SOMETHING'], ['setAnotherThing', 'SET_ANOTHER_THING'], ]; const result = processData(mocked); expect(result).toEqual({ setSomething: () => {} setAnotherThing: () => {} });

Pero falla diciendo esto:

 Expected: "setSomething": [Function setSomething], "setAnotherThing": [Function setAnotherThing], Received: "setSomething": [Function anonymous], "setAnotherThing": [Function anonymous],

¿Alguna forma de probar esto?

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!