Skip to content

Commit

Permalink
Convert done callbacks to async/await in test/unit/custom_spec.js
Browse files Browse the repository at this point in the history
  • Loading branch information
timvandermeij committed Apr 13, 2021
1 parent a1c1e1b commit c1e9f60
Showing 1 changed file with 26 additions and 38 deletions.
64 changes: 26 additions & 38 deletions test/unit/custom_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,50 +35,41 @@ 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);

const renderTask = page.render({
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);

Expand All @@ -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);
});
});

Expand Down

0 comments on commit c1e9f60

Please sign in to comment.