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

663
Views
expect(received).toEqual(expected) // igualdad profunda - Lanza este error cuando la respuesta tiene la condición ternaria

Estoy aprendiendo pruebas unitarias con Jest. Esta es la función que intento probar.

 import axios from "axios"; export const call = async () => { return axios.get("https://www.example.com").then((resp) =>{ const response = resp.data let userData = { title : response.title ? response.title : "", url : response.url ? response.url : "", date : response.date ? response.date : " ", id : response.id ? response.id : "", email: response.email ? response.email : "" } return Promise.resolve(userData) }) }

aquí está el archivo test.js ---

 import axios from "axios" import {call} from './components/call' jest.mock('axios') const expectedResult = { title:"hello" } const resp ={ data : expectedResult } describe("test", ()=>{ test("demo-test", async ()=>{ axios.get.mockResolvedValueOnce(resp) const response = await call() expect(response).toEqual(expectedResult) console.log("axios.get() returns >>>", axios.get.mock.results[0]); expect(axios.get).toHaveBeenCalledWith("https://www.example.com") }) })

Aquí está el error que estoy recibiendo

 expect(received).toEqual(expected) // deep equality - Expected - 0 + Received + 4 Object { + "date": " ", + "email": "", + "id": "", "title": "hello", + "url": "", } 16 | axios.get.mockResolvedValueOnce(resp) 17 | const response = await call() > 18 | expect(response).toEqual(expectedResult) | ^ 19 | 20 | console.log("axios.get() returns >>>", axios.get.mock.results[0]); 21 | expect(axios.get).toHaveBeenCalledWith("https://google.com") FAIL src/call.test.js (7.597 s)

En call.js, cuando userData no tiene condiciones ternarias, la prueba pasa. Pero cuando pongo la condición ternaria, la prueba falla con el error anterior. Por favor, ayúdame. Cómo resolver este problema.

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!