Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/packages/i18n/src/intl/number.test.ts
T

28 lines
967 B
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, test } from "vitest";
import { formatCompactNumber, formatNumber, formatPercent } from "./number.js";
describe("formatNumber", () => {
test("formats decimals per locale", () => {
expect(formatNumber(1234.5, { locale: "de-DE" })).toBe("1.234,5");
expect(formatNumber(1234.5, { locale: "en-US" })).toBe("1,234.5");
});
test("respects fraction digits", () => {
expect(formatNumber(1, { locale: "en-US", minimumFractionDigits: 2 })).toBe("1.00");
});
});
describe("formatPercent", () => {
test("renders a percent sign per locale", () => {
expect(formatPercent(0.25, { locale: "en-US" })).toBe("25%");
// German uses non-breaking space U+00A0 between number and sign.
expect(formatPercent(0.25, { locale: "de-DE" })).toBe("25 %");
});
});
describe("formatCompactNumber", () => {
test("collapses large numbers", () => {
expect(formatCompactNumber(1500, { locale: "en-US" })).toBe("1.5K");
});
});