Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
1.3 kB · 44 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445import { describe, expect, it } from "vitest";import { formatViewers, isPositiveCount } from "./format";
describe("formatViewers", () => { it("returns null for null input", () => { expect(formatViewers(null)).toBeNull(); });
it("returns null for undefined input", () => { expect(formatViewers(undefined as unknown as null)).toBeNull(); });
it("formats numbers below 1000 as locale strings", () => { expect(formatViewers(42)).toBe("42"); expect(formatViewers(999)).toBe("999"); });
it("formats thousands with K suffix", () => { expect(formatViewers(1000)).toBe("1.0K"); expect(formatViewers(1500)).toBe("1.5K"); expect(formatViewers(999999)).toBe("1000.0K"); });
it("formats millions with M suffix", () => { expect(formatViewers(1_000_000)).toBe("1.0M"); expect(formatViewers(2_500_000)).toBe("2.5M"); });
it("formats zero", () => { expect(formatViewers(0)).toBe("0"); });});
describe("isPositiveCount", () => { it("hides missing and zero-value social counters", () => { expect(isPositiveCount(undefined)).toBe(false); expect(isPositiveCount(null)).toBe(false); expect(isPositiveCount(0)).toBe(false); });
it("shows positive social counters", () => { expect(isPositiveCount(1)).toBe(true); });});