I’m wondering if anyone has been able to implement something like jest.spyOn(global, 'Date').mockImplementation(() => now);
inside of Deno.
I have looked through the documentation for the mock in the Deno documentation here and I have looked through the mock time here however this doesn’t look like it will replace the new Date()
with the mocked implementation.
2
Answers
You can overwrite any global variable directly — they’re accessible as properties/methods on
globalThis
.Here’s an example (that’s not specific to any testing framework) which replaces the global
Date
class with an example class that also has a method namedtoString
:https://github.com/hustcc/jest-date-mock might help you as ready solution