[api-minor] Reduce duplication in the "gets non-existent page" unit-test

This commit is contained in:
Jonas Jenwald 2022-02-24 11:20:27 +01:00
parent 2bb96a708c
commit 2be8036eb7
2 changed files with 16 additions and 33 deletions

View File

@ -2848,7 +2848,7 @@ class WorkerTransport {
pageNumber <= 0 ||
pageNumber > this._numPages
) {
return Promise.reject(new Error("Invalid page request"));
return Promise.reject(new Error("Invalid page request."));
}
const pageIndex = pageNumber - 1,

View File

@ -815,40 +815,23 @@ describe("api", function () {
});
it("gets non-existent page", async function () {
let outOfRangePromise = pdfDocument.getPage(100);
let nonIntegerPromise = pdfDocument.getPage(2.5);
let nonNumberPromise = pdfDocument.getPage("1");
const pageNumbers = [
/* outOfRange = */ 100,
/* nonInteger = */ 2.5,
/* nonNumber = */ "1",
];
outOfRangePromise = outOfRangePromise.then(
function () {
throw new Error("shall fail for out-of-range pageNumber parameter");
},
function (reason) {
expect(reason instanceof Error).toEqual(true);
}
);
nonIntegerPromise = nonIntegerPromise.then(
function () {
throw new Error("shall fail for non-integer pageNumber parameter");
},
function (reason) {
expect(reason instanceof Error).toEqual(true);
}
);
nonNumberPromise = nonNumberPromise.then(
function () {
throw new Error("shall fail for non-number pageNumber parameter");
},
function (reason) {
expect(reason instanceof Error).toEqual(true);
}
);
for (const pageNumber of pageNumbers) {
try {
await pdfDocument.getPage(pageNumber);
await Promise.all([
outOfRangePromise,
nonIntegerPromise,
nonNumberPromise,
]);
// Shouldn't get here.
expect(false).toEqual(true);
} catch (reason) {
expect(reason instanceof Error).toEqual(true);
expect(reason.message).toEqual("Invalid page request.");
}
}
});
it("gets page, from /Pages tree with circular reference", async function () {