Vikrant Bhat
Vikrant Bhat

Reputation: 2608

How would one mock an axios({method: "GET", url:"/something"}) request?

axios({method: "GET", url:"/something"})

How can I mock this type of Axios request? I am using jest for testing in a react-native project (without expo)

Upvotes: 1

Views: 612

Answers (1)

ludwiguer
ludwiguer

Reputation: 2245

import axios from 'axios';
 
jest.mock('axios');
 
describe('fetchData', () => {
  it('fetches successfully data from an API', async () => {
    const data = {
      data: {
      },
    };
 
    axios.get.mockImplementationOnce(() => Promise.resolve(data));
  });

Upvotes: 2

Related Questions