I have this dayjs objects:
const today = dayjs.utc(date).startOf("day")
I am trying to mock it using jest but to no avail. Here is the approach I tried:
jest.mock("dayjs", () => ({
extend: jest.fn(),
utc: jest.fn((...args) => {
const dayjs = jest.requireActual("dayjs");
dayjs.extend(jest.requireActual("dayjs/plugin/utc"));
return dayjs
.utc(args.filter((arg) => arg).length > 0 ? args : mockDate)
.startOf("day");
}),
startOf: jest.fn().mockReturnThis(),
}));
I also tried this:
jest.mock("dayjs", () => ({
extend: jest.fn(),
utc: jest.fn((...args) => ({
startOf: jest.fn(() => {
const dayjs = jest.requireActual("dayjs");
dayjs.extend(jest.requireActual("dayjs/plugin/utc"));
return dayjs
.utc(args.filter((arg) => arg).length > 0 ? args : mockEventData)
.startOf("day");
}),
})),
}));
Both are not working. Anyone got an advice?