From 0daab88a486bd62d1d9cf5dacd48e00c87cf4a9e Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 10 Feb 2022 11:42:42 +0100 Subject: [PATCH] Update two `display_utils` unit-tests to use native functionality rather than the `createObjectURL` helper function Given that most of the code-base is already using native functionality, we can update these unit-tests similarily as well. - For the `blob:`-URL test, we simply use `URL.createObjectURL(...)` and `Blob` directly instead. - For the `data:`-URL test, we simply use `btoa` to do the Base64 encoding and then build the final URL-string. --- test/unit/display_utils_spec.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/unit/display_utils_spec.js b/test/unit/display_utils_spec.js index bcb196e59..55ebe6e7d 100644 --- a/test/unit/display_utils_spec.js +++ b/test/unit/display_utils_spec.js @@ -21,7 +21,7 @@ import { isValidFetchUrl, PDFDateString, } from "../../src/display/display_utils.js"; -import { createObjectURL } from "../../src/shared/util.js"; +import { bytesToString } from "../../src/shared/util.js"; import { isNodeJS } from "../../src/shared/is_node.js"; describe("display_utils", function () { @@ -320,7 +320,9 @@ describe("display_utils", function () { pending("Blob in not supported in Node.js."); } const typedArray = new Uint8Array([1, 2, 3, 4, 5]); - const blobUrl = createObjectURL(typedArray, "application/pdf"); + const blobUrl = URL.createObjectURL( + new Blob([typedArray], { type: "application/pdf" }) + ); // Sanity check to ensure that a "blob:" URL was returned. expect(blobUrl.startsWith("blob:")).toEqual(true); @@ -328,12 +330,9 @@ describe("display_utils", function () { }); it('gets fallback filename from query string appended to "data:" URL', function () { - const typedArray = new Uint8Array([1, 2, 3, 4, 5]); - const dataUrl = createObjectURL( - typedArray, - "application/pdf", - /* forceDataSchema = */ true - ); + const typedArray = new Uint8Array([1, 2, 3, 4, 5]), + str = bytesToString(typedArray); + const dataUrl = `data:application/pdf;base64,${btoa(str)}`; // Sanity check to ensure that a "data:" URL was returned. expect(dataUrl.startsWith("data:")).toEqual(true);