Convert done callbacks to async/await in test/unit/primitives_spec.js

This commit is contained in:
Tim van der Meij 2021-04-11 19:56:58 +02:00
parent a56ffb92be
commit 99dc0d6b65
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762

View File

@ -169,40 +169,28 @@ describe("primitives", function () {
).toEqual(testFontFile); ).toEqual(testFontFile);
}); });
it("should asynchronously fetch unknown keys", function (done) { it("should asynchronously fetch unknown keys", async function () {
const keyPromises = [ const keyPromises = [
dictWithManyKeys.getAsync("Size"), dictWithManyKeys.getAsync("Size"),
dictWithSizeKey.getAsync("FontFile", "FontFile2", "FontFile3"), dictWithSizeKey.getAsync("FontFile", "FontFile2", "FontFile3"),
]; ];
Promise.all(keyPromises) const values = await Promise.all(keyPromises);
.then(function (values) { expect(values[0]).toBeUndefined();
expect(values[0]).toBeUndefined(); expect(values[1]).toBeUndefined();
expect(values[1]).toBeUndefined();
done();
})
.catch(function (reason) {
done.fail(reason);
});
}); });
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 = [ const keyPromises = [
dictWithManyKeys.getAsync("FontFile3"), dictWithManyKeys.getAsync("FontFile3"),
dictWithManyKeys.getAsync("FontFile2", "FontFile3"), dictWithManyKeys.getAsync("FontFile2", "FontFile3"),
dictWithManyKeys.getAsync("FontFile", "FontFile2", "FontFile3"), dictWithManyKeys.getAsync("FontFile", "FontFile2", "FontFile3"),
]; ];
Promise.all(keyPromises) const values = await Promise.all(keyPromises);
.then(function (values) { expect(values[0]).toEqual(testFontFile3);
expect(values[0]).toEqual(testFontFile3); expect(values[1]).toEqual(testFontFile2);
expect(values[1]).toEqual(testFontFile2); expect(values[2]).toEqual(testFontFile);
expect(values[2]).toEqual(testFontFile);
done();
})
.catch(function (reason) {
done.fail(reason);
});
}); });
it("should callback for each stored key", function () { it("should callback for each stored key", function () {
@ -218,7 +206,7 @@ describe("primitives", function () {
expect(callbackSpyCalls.count()).toEqual(3); 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 fontRef = Ref.get(1, 0);
const xref = new XRefMock([{ ref: fontRef, data: testFontFile }]); const xref = new XRefMock([{ ref: fontRef, data: testFontFile }]);
const fontDict = new Dict(xref); const fontDict = new Dict(xref);
@ -229,15 +217,12 @@ describe("primitives", function () {
testFontFile testFontFile
); );
fontDict const value = await fontDict.getAsync(
.getAsync("FontFile", "FontFile2", "FontFile3") "FontFile",
.then(function (value) { "FontFile2",
expect(value).toEqual(testFontFile); "FontFile3"
done(); );
}) expect(value).toEqual(testFontFile);
.catch(function (reason) {
done.fail(reason);
});
}); });
it("should handle arrays containing indirect objects", function () { it("should handle arrays containing indirect objects", function () {