From 851c394e648f5b13adf00f28f7b23682666bea6b Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 4 Feb 2023 12:26:30 +0100 Subject: [PATCH] Remove the `isEmptyObj` unit-test helper function We should be able to let Jasmine simply compare directly against an actually empty Object, rather than using a manually implemented helper function for that. --- test/unit/metadata_spec.js | 7 ++++--- test/unit/test_utils.js | 10 ---------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/test/unit/metadata_spec.js b/test/unit/metadata_spec.js index bbc8e6760..4d1aeabeb 100644 --- a/test/unit/metadata_spec.js +++ b/test/unit/metadata_spec.js @@ -13,10 +13,11 @@ * limitations under the License. */ -import { isEmptyObj } from "./test_utils.js"; import { Metadata } from "../../src/display/metadata.js"; import { MetadataParser } from "../../src/core/metadata_parser.js"; +const emptyObj = Object.create(null); + function createMetadata(data) { const metadataParser = new MetadataParser(data); return new Metadata(metadataParser.serializable); @@ -136,7 +137,7 @@ describe("metadata", function () { ''; const metadata = createMetadata(data); - expect(isEmptyObj(metadata.getAll())).toEqual(true); + expect(metadata.getAll()).toEqual(emptyObj); }); it('should gracefully handle "junk" before the actual metadata (issue 10395)', function () { @@ -228,7 +229,7 @@ describe("metadata", function () { ''; const metadata = createMetadata(data); - expect(isEmptyObj(metadata.getAll())).toEqual(true); + expect(metadata.getAll()).toEqual(emptyObj); }); it("should not be vulnerable to the billion laughs attack", function () { diff --git a/test/unit/test_utils.js b/test/unit/test_utils.js index 846c2b6c8..54bcade65 100644 --- a/test/unit/test_utils.js +++ b/test/unit/test_utils.js @@ -15,7 +15,6 @@ import { NullStream, StringStream } from "../../src/core/stream.js"; import { Page, PDFDocument } from "../../src/core/document.js"; -import { assert } from "../../src/shared/util.js"; import { isNodeJS } from "../../src/shared/is_node.js"; import { Ref } from "../../src/core/primitives.js"; @@ -144,20 +143,11 @@ function createIdFactory(pageIndex) { return page._localIdFactory; } -function isEmptyObj(obj) { - assert( - typeof obj === "object" && obj !== null, - "isEmptyObj - invalid argument." - ); - return Object.keys(obj).length === 0; -} - export { buildGetDocumentParams, CMAP_PARAMS, createIdFactory, DefaultFileReaderFactory, - isEmptyObj, STANDARD_FONT_DATA_URL, TEST_PDFS_PATH, XRefMock,