From 99dc0d6b65ea956b6201ea0569134ab411286e3a Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 11 Apr 2021 19:56:58 +0200 Subject: [PATCH] Convert done callbacks to async/await in `test/unit/primitives_spec.js` --- test/unit/primitives_spec.js | 47 ++++++++++++------------------------ 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/test/unit/primitives_spec.js b/test/unit/primitives_spec.js index 205b29291..beb148bc2 100644 --- a/test/unit/primitives_spec.js +++ b/test/unit/primitives_spec.js @@ -169,40 +169,28 @@ describe("primitives", function () { ).toEqual(testFontFile); }); - it("should asynchronously fetch unknown keys", function (done) { + it("should asynchronously fetch unknown keys", async function () { const keyPromises = [ dictWithManyKeys.getAsync("Size"), dictWithSizeKey.getAsync("FontFile", "FontFile2", "FontFile3"), ]; - Promise.all(keyPromises) - .then(function (values) { - expect(values[0]).toBeUndefined(); - expect(values[1]).toBeUndefined(); - done(); - }) - .catch(function (reason) { - done.fail(reason); - }); + const values = await Promise.all(keyPromises); + expect(values[0]).toBeUndefined(); + expect(values[1]).toBeUndefined(); }); - it("should asynchronously fetch correct values for multiple stored keys", function (done) { + it("should asynchronously fetch correct values for multiple stored keys", async function () { const keyPromises = [ dictWithManyKeys.getAsync("FontFile3"), dictWithManyKeys.getAsync("FontFile2", "FontFile3"), dictWithManyKeys.getAsync("FontFile", "FontFile2", "FontFile3"), ]; - Promise.all(keyPromises) - .then(function (values) { - expect(values[0]).toEqual(testFontFile3); - expect(values[1]).toEqual(testFontFile2); - expect(values[2]).toEqual(testFontFile); - done(); - }) - .catch(function (reason) { - done.fail(reason); - }); + const values = await Promise.all(keyPromises); + expect(values[0]).toEqual(testFontFile3); + expect(values[1]).toEqual(testFontFile2); + expect(values[2]).toEqual(testFontFile); }); it("should callback for each stored key", function () { @@ -218,7 +206,7 @@ describe("primitives", function () { expect(callbackSpyCalls.count()).toEqual(3); }); - it("should handle keys pointing to indirect objects, both sync and async", function (done) { + it("should handle keys pointing to indirect objects, both sync and async", async function () { const fontRef = Ref.get(1, 0); const xref = new XRefMock([{ ref: fontRef, data: testFontFile }]); const fontDict = new Dict(xref); @@ -229,15 +217,12 @@ describe("primitives", function () { testFontFile ); - fontDict - .getAsync("FontFile", "FontFile2", "FontFile3") - .then(function (value) { - expect(value).toEqual(testFontFile); - done(); - }) - .catch(function (reason) { - done.fail(reason); - }); + const value = await fontDict.getAsync( + "FontFile", + "FontFile2", + "FontFile3" + ); + expect(value).toEqual(testFontFile); }); it("should handle arrays containing indirect objects", function () {