Created
March 28, 2023 12:15
-
-
Save mahdikhashan/c972b1416a8b8c635ee994117cce7be9 to your computer and use it in GitHub Desktop.
Vitest Mock Timezone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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