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

This commit is contained in:
Tim van der Meij 2021-04-11 19:26:38 +02:00
parent a3669a4f0d
commit a2811e925d
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762

View File

@ -289,33 +289,33 @@ describe("util", function () {
});
describe("createPromiseCapability", function () {
it("should resolve with correct data", function (done) {
it("should resolve with correct data", async function () {
const promiseCapability = createPromiseCapability();
expect(promiseCapability.settled).toEqual(false);
promiseCapability.resolve({ test: "abc" });
promiseCapability.promise.then(function (data) {
expect(promiseCapability.settled).toEqual(true);
expect(data).toEqual({ test: "abc" });
done();
}, done.fail);
const data = await promiseCapability.promise;
expect(promiseCapability.settled).toEqual(true);
expect(data).toEqual({ test: "abc" });
});
it("should reject with correct reason", function (done) {
it("should reject with correct reason", async function () {
const promiseCapability = createPromiseCapability();
expect(promiseCapability.settled).toEqual(false);
promiseCapability.reject(new Error("reason"));
promiseCapability.promise.then(done.fail, function (reason) {
expect(promiseCapability.settled).toEqual(true);
try {
await promiseCapability.promise;
// Shouldn't get here.
expect(false).toEqual(true);
} catch (reason) {
expect(promiseCapability.settled).toEqual(true);
expect(reason instanceof Error).toEqual(true);
expect(reason.message).toEqual("reason");
done();
});
}
});
});