mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-10-16 07:25:44 -04:00
test(i18n): cover month labels when Intl defaults to UTC like the native polyfill
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 file changed
+20
@@ -100,6 +100,26 @@ describe("groupByDateBucket", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("month label is right when Intl defaults to UTC (native polyfill)", () => {
|
||||
const RealDTF = Intl.DateTimeFormat;
|
||||
const originalTz = process.env.TZ;
|
||||
try {
|
||||
process.env.TZ = "Pacific/Kiritimati"; // UTC+14
|
||||
// Emulate the polyfill's UTC default while still honouring an explicit timeZone.
|
||||
vi.spyOn(Intl, "DateTimeFormat").mockImplementation(function (
|
||||
locales?: Intl.LocalesArgument,
|
||||
options?: Intl.DateTimeFormatOptions,
|
||||
) {
|
||||
return new RealDTF(locales, { timeZone: "UTC", ...options });
|
||||
} as unknown as typeof Intl.DateTimeFormat);
|
||||
expect(groupByDateBucket([{ date: "2024-12-03" }])[0].label).toBe("December");
|
||||
} finally {
|
||||
vi.restoreAllMocks();
|
||||
if (originalTz === undefined) delete process.env.TZ;
|
||||
else process.env.TZ = originalTz;
|
||||
}
|
||||
});
|
||||
|
||||
test("item 30+ days out goes to month bucket", () => {
|
||||
const result = groupByDateBucket([{ date: "2024-08-15" }]);
|
||||
expect(result).toHaveLength(1);
|
||||
|
||||
Reference in new issue
Block a user