Having trouble with my mock for the getAll method. The error I'm seeing is:
Expected number of calls: 1 Received number of calls: 0
Here are the mock configurations I've set up:
jest.mock("axios", () => {
return {
create: jest.fn(() => ({
get: jest.fn(() => Promise.resolve({ data: [{ name: "test_role" }] })),
post: jest.fn(() => Promise.resolve({ data: { name: "test_role" } })),
put: jest.fn(() => Promise.resolve({ data: { name: "updated_role" } })),
delete: jest.fn(() => Promise.resolve({ data: "" })),
interceptors: {
request: { use: jest.fn(), eject: jest.fn() },
response: { use: jest.fn(), eject: jest.fn() },
},
})),
};
});
And here's my test script:
it("Testing getting all roles", async () => {
//Arrange
const allRoles = [{ name: "test_role" }];
//Act
const result = await role.getAll();
//Assert
expect(JSON.stringify(result.data)).toBe(JSON.stringify(allRoles));
expect(jest.fn()).toHaveBeenCalledTimes(1);
});