Skip to content

Instantly share code, notes, and snippets.

@mahdikhashan
Created March 28, 2023 12:15
Show Gist options
  • Save mahdikhashan/c972b1416a8b8c635ee994117cce7be9 to your computer and use it in GitHub Desktop.
Save mahdikhashan/c972b1416a8b8c635ee994117cce7be9 to your computer and use it in GitHub Desktop.
Vitest Mock Timezone
it("should get the client timezone as a string", () => {
const DateTimeFormat = Intl.DateTimeFormat;
vi.spyOn(global.Intl, "DateTimeFormat").mockImplementation(
(locale, options) =>
new DateTimeFormat(locale, { ...options, timeZone: "Asia/Tehran" })
);
const date: MyDate = new MyDate("2023-03-28T11:06:48+00:00");
expect(date.getClientTZ()).toEqual("Asia/Tehran");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment