Skip to content

Instantly share code, notes, and snippets.

@mikaelhadler
Created November 20, 2019 16:14
Show Gist options
  • Save mikaelhadler/8d7ef309a8e9e79418f8c8325ed89c7d to your computer and use it in GitHub Desktop.
Save mikaelhadler/8d7ef309a8e9e79418f8c8325ed89c7d to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment