Questions tagged [jest-mock-axios]

33 questions
0
votes
1 answer

JS Jest Mocking - expected received undefined error

I have code that uses axios to get some data. const axios = require('axios'); class Users { static async all() { let res = await axios.get('http://localhost:3000/users'); return res.data; } } module.exports =…
Jan Bodnar
  • 10,969
  • 6
  • 68
  • 77
-1
votes
1 answer

TypeError: Cannot read properties of undefined (reading '1')

when try to mock the post call with jest getting error as: TypeError: Cannot read properties of undefined (reading '1') any one help me to understand please? here is the spect code: const mockFn = jest.fn(); axios.post = mockFn; …
3gwebtrain
  • 14,640
  • 25
  • 121
  • 247
-1
votes
1 answer

How to Test a Reactcomponent which has Axios call in componentDidMount using JEST with ENZYME?

Introduction I want to test a component that has axios call in componentDidMount. I have tried all the ways but ever time I'm facing the same issue with axios. Error: axios.get('https://jsonplaceholder.typicode.com/todos/1') | ^ …
Joseph Nannepaga
  • 175
  • 1
  • 3
  • 14
1 2
3