添加此行代码
const mockedAxios = axios as jest.Mocked<typeofaxios>。然后使用mockedAxios调用mockReturnValueOnce。使用您的代码,应该像这样完成:
import myModuleThatCallsAxios from '../myModule';import axios from 'axios';jest.mock('axios');const mockedAxios = axios as jest.Mocked<typeof axios>;it('Calls the GET method as expected', async () => { const expectedResult: string = 'result'; mockedAxios.get.mockReturnValueonce({ data: expectedResult }); const result = await myModuleThatCallsAxios.makeGetRequest(); expect(mockedAxios.get).toHaveBeenCalled(); expect(result).toBe(expectedResult);});


