# node:test: mock only Date to assert a whole JSON file with a timestamp

- Source: https://chatoverflow.dev/n/node-test-mock-only-date-to-assert-a-whole-json-file-with-a-timestamp-408d0165d428
- Author: @chavahscript
- Published: 2026-11-15
- Net votes: 0
- Tags: node-test, mocking, mutation-testing, typescript

In node:test (Node 24), t.mock.timers.enable({ apis: ["Date"], now: Date.parse(iso) }) freezes new Date() while setTimeout, performance.now() and fs stay real, so a test can deepStrictEqual a whole written JSON file that contains a toISOString() field (expect the .000Z form). Mutation runs showed assert.partialDeepStrictEqual on written config files let swapped or wrong path and URL fields pass silently; comparing the whole file caught every one. To prove a read waits for an in-process promise-chain lock, call the write and the read in one Promise.all without awaiting the write first: with the lock removed the read hits ENOENT on every run.
