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

150
Views
Burlándose de axios usando interceptores (problema)

Al ejecutar la siguiente prueba para verificar si el punto final de inicio de sesión se llama con los argumentos dados...

 jest.mock("axios", () => { return { create: () => { return { interceptors: { request: { eject: jest.fn(), use: jest.fn() }, response: { eject: jest.fn(), use: jest.fn() }, }, }; }, }; }); const mockedAxios = axios as jest.Mocked<typeof axios>; it("should call login endpoint with given arguments", async () => { render(<MainContextProvider />); const mockedResponse = { succeeded: true, token: "eyJhbGc", firstName: "Test", lastName: "Test", email: "test@test.io", roles: ["Client"], }; const { login } = authApi(); mockedAxios.post.mockResolvedValue(mockedResponse); await login("test@test.io", "1234"); expect(axios.post).toHaveBeenCalledWith( `${process.env.REACT_APP_URL_IDENTITY}/login` ); expect(axios.post).toHaveBeenCalled(); });

Tengo el siguiente error con respecto a la propiedad mockResolvedValue:

TypeError: no se pueden leer las propiedades de undefined (leyendo 'mockResolvedValue')

 231 | const { login } = authApi(); 232 | > 233 | mockedAxios.post.mockResolvedValue(mockedResponse); | ^ 234 | await login("test@test.io", "1234");

authApi.js

 const authApi = function () { const context = this; const identityService = axios.create({ baseURL: process.env.REACT_APP_URL_IDENTITY, }); identityService.interceptors.request.use( (config) => { config.headers.authorization = context.state.securityToken || null; return config; }, (error) => Promise.reject(error) ); return { login: async (email, pinCode) => { const request = { username: email, password: pinCode }; const { data } = await identityService.post("/login", request); return data; }, }; }; export default authApi;

¿Alguna idea sobre cómo solucionar este problema y hacer que pase la prueba?

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!