Reactjs 财产';getData';不存在于类型';组件类';

Reactjs 财产';getData';不存在于类型';组件类';,reactjs,typescript,jestjs,Reactjs,Typescript,Jestjs,我想用jest模拟axios调用,但在使用此testcase时,仅getData出现错误: jest.mock('axios') const mockAxios = axios as AxiosMock it('make api call to get data', () => { // call this first mockAxios.mockResolvedValue(data) TestPublications.getData() expect(mock

我想用jest模拟axios调用,但在使用此testcase时,仅getData出现错误:

jest.mock('axios')
const mockAxios = axios as AxiosMock

it('make api call to get data', () => {
   // call this first
   mockAxios.mockResolvedValue(data)

   TestPublications.getData()
   expect(mockAxios.get).toHaveBeenCalledWith("http://app30.knipsel.lan:665/v1/publications/crud")
});

我认为您的TestPublications是您的React类,如果您在其中编写的函数不是正常面向对象意义上的方法,那么您需要将
getData
放在您的文件(例如TestPublications.js)的类外,然后将该函数导出到test

请提供最小的代码。否则,由于缺乏细节,问题将被关闭。