'why does the function return what it needs in one place, and in another it returns 'undefined'?
I wrote a test
import {actions} from "./usersPageReducer";
import { usersAPI } from "../api/api";
jest.mock("../api/api");
const usersAPIMock = usersAPI;
usersAPIMock.follow.mockReturnValue(() => ({ data: true }));
describe("follow", () => {
If you remove the comment we get, what we need response = { data: true }
/* const response = usersAPIMock.follow(1, "true");
console.log("res", response); */
it("follow", () => {
const dispatchMock = jest.fn();
const followTest = (userID: number) => {
return async (dispatchMock) => {
dispatchMock(actions.buttonDisabledAC(true, userID));
const result = await usersAPIMock.follow(userID, "true");
But here, for some reason, it returns 'undefined'
if (result.data === true) {
dispatchMock(actions.followAC(userID));
dispatchMock(actions.buttonDisabledAC(false, userID));
}
};
};
const thunk = followTest(1);
thunk(dispatchMock);
expect(dispatchMock).toBeCalledTimes(3);
});
});
Explain why this is happening, what am I doing wrong? And how to do it right?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
