z.date() does not work with vi.setSystemTime() #2764
-
When mocking the system, time with vitest (which uses: CodeSandbox: https://codesandbox.io/p/sandbox/zen-bartik-gg4nn9 it("runs", () => {
const dateSchema = z.coerce.date();
// This Works
console.log(dateSchema.parse("2023-07-19"));
vi.setSystemTime(1689775661);
// This doesn't work
console.log(dateSchema.parse("2023-07-19"));
}); The second parse throws an Error, even through it worked before with the same value:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This seems to have nothing to do with Zod. https://vitest.dev/api/vi.html#vi-setsystemtime you need to use If you found my answer satisfactory, please consider supporting me. Even a small amount is greatly appreciated. Thanks friend! 🙏 |
Beta Was this translation helpful? Give feedback.
This seems to have nothing to do with Zod.
https://vitest.dev/api/vi.html#vi-setsystemtime
you need to use
vi.useFakeTimers()
If you found my answer satisfactory, please consider supporting me. Even a small amount is greatly appreciated. Thanks friend! 🙏
https://github.com/sponsors/JacobWeisenburger