1//axios.js
2const axios = require('axios')
3module.exports = axios.get
4
5//__mocks__/axios.js
6const axios = require('axios')
7
8module.exports = {
9 get: async () => {
10 const url = 'https://jsonplaceholder.typicode.com/posts'
11 const response = await axios.get(url)
12 return response.data
13 }
14}
15
16//__test__/axios.test.js
17const axiosMock = require('../axios')
18
19test('async axios action users with mock', async (done) => {
20 const url = 'https://jsonplaceholder.typicode.com/users'
21 response = await axiosMock(url)
22
23 expect(response).toBeDefined()
24 expect(response.length).toBe(100);
25 done()
26});