mikaelhadler
11/20/2019 - 4:14 PM

Testing requests with jest and axios using a custom instance

Testing requests with jest and axios using a custom instance

const mockAxios = jest.genMockFromModule('axios')
mockAxios.get = jest.fn(() => Promise.resolve({ data: {} }))
mockAxios.post = jest.fn(() => Promise.resolve({ data: {} }))
mockAxios.put = jest.fn(() => Promise.resolve({ data: {} }))
mockAxios.patch = jest.fn(() => Promise.resolve({ data: {} }))
mockAxios.create = jest.fn(() => mockAxios)

export default mockAxios