webpack/test/SizeFormatHelpers.unittest.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

/* globals describe, it, beforeEach */
"use strict";
const SizeFormatHelpers = require("../lib/SizeFormatHelpers");
describe("SizeFormatHelpers", () => {
describe("formatSize", () => {
it("should handle zero size", () => {
2018-01-24 20:17:21 +08:00
expect(SizeFormatHelpers.formatSize(0)).toBe("0 bytes");
});
it("should handle bytes", () => {
2018-01-24 20:17:21 +08:00
expect(SizeFormatHelpers.formatSize(1000)).toBe("1000 bytes");
});
it("should handle integer kibibytes", () => {
2018-01-24 20:17:21 +08:00
expect(SizeFormatHelpers.formatSize(2048)).toBe("2 KiB");
});
it("should handle float kibibytes", () => {
2018-01-24 20:17:21 +08:00
expect(SizeFormatHelpers.formatSize(2560)).toBe("2.5 KiB");
});
it("should handle integer mebibytes", () => {
2018-01-24 20:17:21 +08:00
expect(SizeFormatHelpers.formatSize(10 * 1024 * 1024)).toBe("10 MiB");
});
it("should handle float mebibytes", () => {
2018-01-24 20:17:21 +08:00
expect(SizeFormatHelpers.formatSize(12.5 * 1024 * 1024)).toBe("12.5 MiB");
});
it("should handle integer gibibytes", () => {
2018-02-25 18:46:17 +08:00
expect(SizeFormatHelpers.formatSize(3 * 1024 * 1024 * 1024)).toBe(
"3 GiB"
);
});
it("should handle float gibibytes", () => {
2018-02-25 18:46:17 +08:00
expect(SizeFormatHelpers.formatSize(1.2 * 1024 * 1024 * 1024)).toBe(
"1.2 GiB"
);
});
2018-03-29 21:28:03 +08:00
it("should handle undefined/NaN", () => {
expect(SizeFormatHelpers.formatSize(undefined)).toBe("unknown size");
expect(SizeFormatHelpers.formatSize(NaN)).toBe("unknown size");
2018-03-29 21:28:03 +08:00
});
});
});