Skip to content
Source
Sign inSign up

formatBytes.test.ts

26 lines700 Bytes

1import { describe, expect, it } from "vite-plus/test";
2​
3import { formatBytes } from "./formatBytes";
4​
5describe("formatBytes", () => {
6 it.each([
7 [0, "0 B"],
8 [1_023, "1023 B"],
9 [1_024, "1.00 KB"],
10 [1_536, "1.50 KB"],
11 [1_047_552, "1023 KB"],
12 [1_048_576, "1.00 MB"],
13 [5 * 1_024 ** 4, "5.00 TB"],
14 [2_048 * 1_024 ** 4, "2048 TB"],
15 ])("formats %d bytes as %s", (value, label) => {
16 expect(formatBytes(value)).toBe(label);
17 });
18​
19 it.each([
20 [1_023.6, "1.00 KB"],
21 [1_048_100, "1.00 MB"],
22 [1_073_217_536, "1.00 GB"],
23 ])("moves %d bytes to the next unit when rounding reaches 1024", (value, label) => {
24 expect(formatBytes(value)).toBe(label);
25 });
26});