client/index.js我有一个使用 axios 发出请求的函数
import axios from "axios";
const createRequest = async (url, method) => {
const response = await axios({
url: url,
method: method
});
return response;
};
export default { createRequest };
Run Code Online (Sandbox Code Playgroud)
我想使用 测试这个函数jest,所以我创建了client/index.test.js
import { jest } from "@jest/globals";
import axios from "axios";
import client from "./";
jest.doMock('axios', () => jest.fn(() => Promise.resolve()));
describe("Client", () => {
it("should call axios and return a response", async () => {
const response = await client.createRequest('http://localhost/', 'GET'); …Run Code Online (Sandbox Code Playgroud)