bun:test lets you change what time it is in your tests.
This works with any of the following:
Date.nownew Date()new Intl.DateTimeFormat().format()
setSystemTime
To change the system time, usesetSystemTime:
useFakeTimers and useRealTimers are also supported, so existing tests that use them keep working:
Reset the system time
To reset the system time, pass no arguments tosetSystemTime:
Get mocked time with jest.now()
When the time is mocked (withsetSystemTime or useFakeTimers), jest.now() returns the current mocked timestamp:
Date object.
Set the time zone
By default,bun test runs in UTC (Etc/UTC). To change the time zone, either pass the TZ environment variable to bun test:
terminal
process.env.TZ at runtime:
Unlike in Jest, you can change the time zone multiple times at runtime.