Reputation: 2608
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
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