Skip to content

Commit

Permalink
Move the isEmptyObj helper function from src/shared/util.js to `t…
Browse files Browse the repository at this point in the history
…est/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.
  • Loading branch information
Snuffleupagus committed Jun 9, 2020
1 parent 159e13c commit 88fdb48
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
8 changes: 0 additions & 8 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down Expand Up @@ -931,7 +924,6 @@ export {
isArrayBuffer,
isArrayEqual,
isBool,
isEmptyObj,
isNum,
isString,
isSameOrigin,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/metadata_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
9 changes: 9 additions & 0 deletions test/unit/test_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -184,4 +192,5 @@ export {
buildGetDocumentParams,
TEST_PDFS_PATH,
createIdFactory,
isEmptyObj,
};
11 changes: 0 additions & 11 deletions test/unit/util_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
createValidAbsoluteUrl,
isArrayBuffer,
isBool,
isEmptyObj,
isNum,
isSameOrigin,
isString,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 88fdb48

Please sign in to comment.