Skip to content

Commit

Permalink
✅ test withResolvers()
Browse files Browse the repository at this point in the history
If we want to backport `withResolvers()` to v3, it will need to have
tests in order to ensure that it behaves the same even though the
implementation will be significantly different
  • Loading branch information
cowboyd committed Jan 3, 2025
1 parent dab567d commit 76b1ca4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/with-resolvers.test.ts
Original file line number Diff line number Diff line change
@@ -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<string>();
resolve("hello");
await expect(run(() => operation)).resolves.toEqual("hello");
});
it("resolves only once", async () => {
let { operation, resolve, reject } = withResolvers<string>();
resolve("hello");
reject(new Error("boom!"));
resolve("goodbye");
await expect(run(() => operation)).resolves.toEqual("hello");
});
it("rejects", async () => {
let { operation, reject } = withResolvers<string>();
reject(new Error("boom!"));
await expect(run(() => operation)).rejects.toMatchObject({
message: "boom!",
});
});
it("rejects only once", async () => {
let { operation, reject } = withResolvers<string>();
reject(new Error("boom!"));
reject(new Error("bam!"));
await expect(run(() => operation)).rejects.toMatchObject({
message: "boom!",
});
});
});

0 comments on commit 76b1ca4

Please sign in to comment.