From e787247c6f48735e78d77de786277a6071c7bde3 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 18 Feb 2026 03:27:26 +0000 Subject: [PATCH] test(utils): add unit tests for todayDateStr and nowUnix Add comprehensive unit tests for `todayDateStr` and `nowUnix` in `src/utils.mjs`. These tests use `node:test`'s mock timers to ensure deterministic execution, verifying that the date formatting and timestamp generation behave as expected. - `todayDateStr`: verified correct YYYY-MM-DD format - `nowUnix`: verified correct integer timestamp generation Co-authored-by: PR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> --- test/utils.test.mjs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/test/utils.test.mjs b/test/utils.test.mjs index 06b2b94..de323bf 100644 --- a/test/utils.test.mjs +++ b/test/utils.test.mjs @@ -1,8 +1,30 @@ import { describe, it } from 'node:test'; import assert from 'node:assert'; -import { getIsoWeekStr } from '../src/utils.mjs'; +import { getIsoWeekStr, todayDateStr, nowUnix } from '../src/utils.mjs'; describe('Date Utilities', () => { + describe('todayDateStr', () => { + it('returns current date in YYYY-MM-DD format', (t) => { + t.mock.timers.enable({ apis: ['Date'] }); + // 2023-10-25 12:00:00 UTC + const date = new Date('2023-10-25T12:00:00Z'); + t.mock.timers.setTime(date.getTime()); + + assert.strictEqual(todayDateStr(), '2023-10-25'); + }); + }); + + describe('nowUnix', () => { + it('returns current unix timestamp', (t) => { + t.mock.timers.enable({ apis: ['Date'] }); + const timeMs = 1700000000000; + t.mock.timers.setTime(timeMs); + + // 1700000000000 / 1000 = 1700000000 + assert.strictEqual(nowUnix(), 1700000000); + }); + }); + describe('getIsoWeekStr', () => { it('returns correct ISO week for simple cases', () => { assert.strictEqual(getIsoWeekStr('2023-01-02'), '2023-W01'); // Mon