diff --git a/test/with-resolvers.test.ts b/test/with-resolvers.test.ts new file mode 100644 index 00000000..e0c0802e --- /dev/null +++ b/test/with-resolvers.test.ts @@ -0,0 +1,32 @@ +import { run, withResolvers } from "../mod.ts"; +import { describe, expect, it } from "./suite.ts"; + +describe("withResolvers()", () => { + it("resolves", async () => { + let { operation, resolve } = withResolvers(); + resolve("hello"); + await expect(run(() => operation)).resolves.toEqual("hello"); + }); + it("resolves only once", async () => { + let { operation, resolve, reject } = withResolvers(); + resolve("hello"); + reject(new Error("boom!")); + resolve("goodbye"); + await expect(run(() => operation)).resolves.toEqual("hello"); + }); + it("rejects", async () => { + let { operation, reject } = withResolvers(); + reject(new Error("boom!")); + await expect(run(() => operation)).rejects.toMatchObject({ + message: "boom!", + }); + }); + it("rejects only once", async () => { + let { operation, reject } = withResolvers(); + reject(new Error("boom!")); + reject(new Error("bam!")); + await expect(run(() => operation)).rejects.toMatchObject({ + message: "boom!", + }); + }); +});