I'm trying to use "axios-mock-adapter" lib to mock my API requests.
Following the documentation, I need to create an instance of MockAdapter and use it in test cases. But actually, it returns a Promise and follows the next error "mock.onGet is not a function".
Code:
import MockAdapter from "axios-mock-adapter";
import axios from "axios";
const mock = new MockAdapter(axios.create());
it("should mock", () => {
mock.onGet("/test", { data: "test" });
expect(true).toBeTruthy();
});
Error:
mock.onGet is not a function
TypeError: mock.onGet is not a function
at Object.<anonymous> (/Users/api/__tests__/api.test.ts:7:8)
at Promise.then.completed (/Users/node_modules/react-scripts/node_modules/jest-circus/build/utils.js:391:28)
at new Promise (<anonymous>)
I tried to resolve a promise that MockAdapter returns, but it throws a new error.
axios: ^1.3.3 axios-mock-adapter: ^1.21.2