-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Hi everyone, one question, I'm using jest": "^29.7.0", "jest-fixed-jsdom": "^0.0.9" and "msw": "^2.10.2" into a project, and basically doesn't mock my functions as the following
const dispatch = jest.fn();
jest.mock("../../../store/hooks", () => ({
...jest.requireActual("../../../store/hooks"),
useAppDispatch: () => dispatch,
}));
jest.mock("../../../store/slices/ecommerce/thunks", () => ({
...jest.requireActual("../../../store/slices/ecommerce/thunks"),
startAddToCart: jest.fn(),
}));
So, i get an error because dispatch is not called
But, if i use jest.spyOn instead of the jest.mock, it works perfectly as the following
import * as hooks from "../../../store/hooks";
import * as thunks from "../../../store/slices/ecommerce/thunks";
const dispatch = jest.fn();
jest.spyOn(hooks, "useAppDispatch").mockImplementation(() => dispatch);
jest.spyOn(thunks, "startAddToCart").mockImplementation(jest.fn());
I don't know if it's an mistake by jest-fixed-jsdom or msw, because i have another project with the same version of jest but without msw neither jest-fixed-jsdom, and this work perfectly using jest.mock
Metadata
Metadata
Assignees
Labels
No labels