开玩笑-TypeError:(0,something())不是函数

时间:2018-08-15 13:05:04

标签: javascript reactjs axios jestjs

我使用axios并获取一些数据:

export const getSomething = () => {
  return axios
    .get(`/somehting`, proxyConfig)
    .then(response => {
      return response.data;
    })
    .catch(error => {
      console.log(error.message);
      httpErrors(error);
    });
};

开玩笑:

import mockAxios from "jest-mock-axios";
import { getSomething } from "./Api";

afterEach(() => {
  // cleaning up the mess left behind the previous test
  mockAxios.reset();
});

it("should get some data..", () => {
  const dummyF = jest.fn();
  const dummyCatch = jest.fn();

  getSomething()
    .then(dummyF)
    .catch(dummyCatch);

  mockAxios.mockResponse({ data: "" });
  expect(mockAxios.get).toHaveBeenCalledWith(
    "/somehting"
  );
  expect(dummyF).toHaveBeenCalledTimes(1);
  expect(dummyCatch).not.toHaveBeenCalled();
});

但是我遇到以下错误:

TypeError: (0 , _Api.getSomething) is not a function

我可以从其他文件调用该方法,是因为我在getSomething方法上使用ES6语法吗?

0 个答案:

没有答案