--- name: Set the system time in Bun's test runner --- Bun's test runner supports setting the system time programmatically with the `setSystemTime` function. ```ts import { test, expect, setSystemTime } from "bun:test"; test("party like it's 1999", () => { const date = new Date("1999-01-01T00:00:00.000Z"); setSystemTime(date); // it's now January 1, 1999 const now = new Date(); expect(now.getFullYear()).toBe(1999); expect(now.getMonth()).toBe(0); expect(now.getDate()).toBe(1); }); ``` --- The `setSystemTime` function is commonly used on conjunction with [Lifecycle Hooks](/docs/test/lifecycle) to configure a testing environment with a determinstic "fake clock". ```ts import { test, expect, beforeAll, setSystemTime } from "bun:test"; beforeAll(() => { const date = new Date("1999-01-01T00:00:00.000Z"); setSystemTime(date); // it's now January 1, 1999 }); // tests... ``` --- To reset the system clock to the actual time, call `setSystemTime` with no arguments. ```ts import { test, expect, beforeAll, setSystemTime } from "bun:test"; setSystemTime(); // reset to actual time ``` --- See [Docs > Test Runner > Date and time](/docs/test/time) for complete documentation on mocking with the Bun test runner. Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets/text-encoder.test.js (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-03-02Update global.zigGravatar Jarred Sumner 1-0/+17
2022-03-02Update fs.zigGravatar Jarred Sumner 1-0/+3
2022-03-02[bun run] Set more environment variablesGravatar Jarred Sumner 2-0/+55
2022-03-02clean up error message when CLI flag is invalidGravatar Jarred Sumner 1-1/+4
2022-03-02add `bun pm cache` and `bun pm cache rm` commandsGravatar Jarred Sumner 1-0/+20
2022-03-01[bun.js] `ResolveError.prototype.toString()` `BuildError.prototype.toString()`Gravatar Jarred Sumner 1-2/+94
2022-03-01add `allowBunRuntime` and `autoImportJSX` flags to Bun.TranspilerGravatar Jarred Sumner 1-1/+32
2022-03-01cleanup code that checks if it should send an HTTP bodyGravatar Jarred Sumner 2-6/+18
2022-03-01[JS Parser] Fix bug with `super` from adding class static blocksGravatar Jarred Sumner 1-1/+12
2022-03-01Update bundler.zigGravatar Jarred Sumner 1-1/+5
2022-03-01Remove unused boolGravatar Jarred Sumner 1-3/+0
2022-03-01[bun.js] Allow disabling runtime imports so bun can build for nodeGravatar Jarred Sumner 3-5/+11
2022-03-01[JS Parser] Make auto importing JSX a flag so the API is easierGravatar Jarred Sumner 1-295/+297
2022-03-01cleanupGravatar Jarred Sumner 1-2/+2
2022-03-01Update javascript.zigGravatar Jarred Sumner 1-50/+0
2022-03-01[bun.js] shim async fsGravatar Jarred Sumner 2-36/+226
2022-03-01[bun.js] Implement `setTimeout`, `setInterval`, `clearTimeout`, `clearInterval`Gravatar Jarred Sumner 11-41/+295
2022-02-27Update transpiler.test.jsGravatar Jarred Sumner 1-0/+8
2022-02-27[TS] Make `export {type foo}` output consistent with TS parserGravatar Jarred Sumner 1-3/+45
2022-02-27WASMGravatar Jarred Sumner 83-690/+10789