Something went wrong. Try again.
A set of JavaScript filters and components meant to replicate Django's humanize
Something went wrong. Try again.
human-eyes filesizeformat.test.js
2.0 kB · 77 lines
JavaScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778import { describe, it, expect } from "vitest";import { filesizeformat } from "./filesizeformat.js";
describe("filesizeformat", () => { it("formats 0 as '0 bytes'", () => { expect(filesizeformat(0)).toBe("0 bytes"); });
it("formats 1 as '1 byte'", () => { expect(filesizeformat(1)).toBe("1 byte"); });
it("formats 512 as '512 bytes'", () => { expect(filesizeformat(512)).toBe("512 bytes"); });
it("formats 1023 as '1023 bytes'", () => { expect(filesizeformat(1023)).toBe("1023 bytes"); });
// KB it("formats 1024 as '1.0 KB'", () => { expect(filesizeformat(1 * 1024)).toBe("1.0 KB"); });
it("formats 1740 as '1.7 KB'", () => { expect(filesizeformat(1740)).toBe("1.7 KB"); });
// MB it("formats 1 * 1024 ** 2 as '1.0 MB'", () => { expect(filesizeformat(1 * 1024 ** 2)).toBe("1.0 MB"); });
it("formats 123456789 as '117.7 MB'", () => { expect(filesizeformat(123456789)).toBe("117.7 MB"); });
// GB it("formats 1 * 1024 ** 3 as '1.0 GB'", () => { expect(filesizeformat(1 * 1024 ** 3)).toBe("1.0 GB"); });
it("formats 3373256576 as '3.1 GB'", () => { expect(filesizeformat(3373256576)).toBe("3.1 GB"); });
it("formats 23489218876 as '21.9 GB'", () => { expect(filesizeformat(23489218876)).toBe("21.9 GB"); });
// TB it("formats 1 * 1024 ** 4 as '1.0 TB'", () => { expect(filesizeformat(1 * 1024 ** 4)).toBe("1.0 TB"); });
it("formats 1649267441664 as '1.5 TB'", () => { expect(filesizeformat(1649267441664)).toBe("1.5 TB"); });
// PB it("formats 1 * 1024 ** 5 as '1.0 PB'", () => { expect(filesizeformat(1 * 1024 ** 5)).toBe("1.0 PB"); });
it("formats 92723489213592406 as '82.4 PB'", () => { expect(filesizeformat(92723489213592406)).toBe("82.4 PB"); });
it("returns '0 bytes' for negative values", () => { expect(filesizeformat(-100)).toBe("0 bytes"); });
it("returns '0 bytes' for NaN", () => { expect(filesizeformat("not a number")).toBe("0 bytes"); });});