From c1e9f6025f7c530a0e81458f34eb2532b3e49f22 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 11 Apr 2021 20:11:42 +0200 Subject: [PATCH] Convert done callbacks to async/await in `test/unit/custom_spec.js` --- test/unit/custom_spec.js | 64 ++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 38 deletions(-) diff --git a/test/unit/custom_spec.js b/test/unit/custom_spec.js index aa393af7c..562524778 100644 --- a/test/unit/custom_spec.js +++ b/test/unit/custom_spec.js @@ -35,28 +35,22 @@ describe("custom canvas rendering", function () { let loadingTask; let page; - beforeAll(function (done) { + beforeAll(async function () { CanvasFactory = new DefaultCanvasFactory(); loadingTask = getDocument(transparentGetDocumentParams); - loadingTask.promise - .then(function (doc) { - return doc.getPage(1); - }) - .then(function (data) { - page = data; - done(); - }) - .catch(done.fail); + const doc = await loadingTask.promise; + const data = await doc.getPage(1); + page = data; }); - afterAll(function (done) { + afterAll(async function () { CanvasFactory = null; page = null; - loadingTask.destroy().then(done); + await loadingTask.destroy(); }); - it("renders to canvas with a default white background", function (done) { + it("renders to canvas with a default white background", async function () { const viewport = page.getViewport({ scale: 1 }); const canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height); @@ -64,21 +58,18 @@ describe("custom canvas rendering", function () { canvasContext: canvasAndCtx.context, viewport, }); - renderTask.promise - .then(function () { - expect(getTopLeftPixel(canvasAndCtx.context)).toEqual({ - r: 255, - g: 255, - b: 255, - a: 255, - }); - CanvasFactory.destroy(canvasAndCtx); - done(); - }) - .catch(done.fail); + await renderTask.promise; + + expect(getTopLeftPixel(canvasAndCtx.context)).toEqual({ + r: 255, + g: 255, + b: 255, + a: 255, + }); + CanvasFactory.destroy(canvasAndCtx); }); - it("renders to canvas with a custom background", function (done) { + it("renders to canvas with a custom background", async function () { const viewport = page.getViewport({ scale: 1 }); const canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height); @@ -87,18 +78,15 @@ describe("custom canvas rendering", function () { viewport, background: "rgba(255,0,0,1.0)", }); - renderTask.promise - .then(function () { - expect(getTopLeftPixel(canvasAndCtx.context)).toEqual({ - r: 255, - g: 0, - b: 0, - a: 255, - }); - CanvasFactory.destroy(canvasAndCtx); - done(); - }) - .catch(done.fail); + await renderTask.promise; + + expect(getTopLeftPixel(canvasAndCtx.context)).toEqual({ + r: 255, + g: 0, + b: 0, + a: 255, + }); + CanvasFactory.destroy(canvasAndCtx); }); });