From 88fdb482b097b7d899215838f657352deb4e1199 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 9 Jun 2020 16:48:03 +0200 Subject: [PATCH] Move the `isEmptyObj` helper function from `src/shared/util.js` to `test/unit/test_utils.js` Since this helper function is no longer used anywhere in the main code-base, but only in a couple of unit-tests, it's thus being moved to a more appropriate spot. Finally, the implementation of `isEmptyObj` is also tweaked slightly by removing the manual loop. --- src/shared/util.js | 8 -------- test/unit/metadata_spec.js | 2 +- test/unit/test_utils.js | 9 +++++++++ test/unit/util_spec.js | 11 ----------- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/shared/util.js b/src/shared/util.js index eeb666d20..64b07f526 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -793,13 +793,6 @@ function utf8StringToString(str) { return unescape(encodeURIComponent(str)); } -function isEmptyObj(obj) { - for (const key in obj) { - return false; - } - return true; -} - function isBool(v) { return typeof v === "boolean"; } @@ -931,7 +924,6 @@ export { isArrayBuffer, isArrayEqual, isBool, - isEmptyObj, isNum, isString, isSameOrigin, diff --git a/test/unit/metadata_spec.js b/test/unit/metadata_spec.js index 710a8fdb7..02eabd271 100644 --- a/test/unit/metadata_spec.js +++ b/test/unit/metadata_spec.js @@ -13,7 +13,7 @@ * limitations under the License. */ -import { isEmptyObj } from "../../src/shared/util.js"; +import { isEmptyObj } from "./test_utils.js"; import { Metadata } from "../../src/display/metadata.js"; describe("metadata", function () { diff --git a/test/unit/test_utils.js b/test/unit/test_utils.js index 09d2827a2..a1156c5a8 100644 --- a/test/unit/test_utils.js +++ b/test/unit/test_utils.js @@ -175,6 +175,14 @@ function createIdFactory(pageIndex) { return page.idFactory; } +function isEmptyObj(obj) { + assert( + typeof obj === "object" && obj !== null, + "isEmptyObj - invalid argument." + ); + return Object.keys(obj).length === 0; +} + export { DOMFileReaderFactory, NodeFileReaderFactory, @@ -184,4 +192,5 @@ export { buildGetDocumentParams, TEST_PDFS_PATH, createIdFactory, + isEmptyObj, }; diff --git a/test/unit/util_spec.js b/test/unit/util_spec.js index eca89e41f..8d5a76968 100644 --- a/test/unit/util_spec.js +++ b/test/unit/util_spec.js @@ -19,7 +19,6 @@ import { createValidAbsoluteUrl, isArrayBuffer, isBool, - isEmptyObj, isNum, isSameOrigin, isString, @@ -89,16 +88,6 @@ describe("util", function () { }); }); - describe("isEmptyObj", function () { - it("handles empty objects", function () { - expect(isEmptyObj({})).toEqual(true); - }); - - it("handles non-empty objects", function () { - expect(isEmptyObj({ foo: "bar" })).toEqual(false); - }); - }); - describe("isNum", function () { it("handles numeric values", function () { expect(isNum(1)).toEqual(true);