Convert done callbacks to async/await in test/unit/util_spec.js
This commit is contained in:
parent
a3669a4f0d
commit
a2811e925d
@ -289,33 +289,33 @@ describe("util", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("createPromiseCapability", function () {
|
describe("createPromiseCapability", function () {
|
||||||
it("should resolve with correct data", function (done) {
|
it("should resolve with correct data", async function () {
|
||||||
const promiseCapability = createPromiseCapability();
|
const promiseCapability = createPromiseCapability();
|
||||||
expect(promiseCapability.settled).toEqual(false);
|
expect(promiseCapability.settled).toEqual(false);
|
||||||
|
|
||||||
promiseCapability.resolve({ test: "abc" });
|
promiseCapability.resolve({ test: "abc" });
|
||||||
|
|
||||||
promiseCapability.promise.then(function (data) {
|
const data = await promiseCapability.promise;
|
||||||
expect(promiseCapability.settled).toEqual(true);
|
expect(promiseCapability.settled).toEqual(true);
|
||||||
|
expect(data).toEqual({ test: "abc" });
|
||||||
expect(data).toEqual({ test: "abc" });
|
|
||||||
done();
|
|
||||||
}, done.fail);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should reject with correct reason", function (done) {
|
it("should reject with correct reason", async function () {
|
||||||
const promiseCapability = createPromiseCapability();
|
const promiseCapability = createPromiseCapability();
|
||||||
expect(promiseCapability.settled).toEqual(false);
|
expect(promiseCapability.settled).toEqual(false);
|
||||||
|
|
||||||
promiseCapability.reject(new Error("reason"));
|
promiseCapability.reject(new Error("reason"));
|
||||||
|
|
||||||
promiseCapability.promise.then(done.fail, function (reason) {
|
try {
|
||||||
expect(promiseCapability.settled).toEqual(true);
|
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 instanceof Error).toEqual(true);
|
||||||
expect(reason.message).toEqual("reason");
|
expect(reason.message).toEqual("reason");
|
||||||
done();
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user