forked from get-convex/convex-helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.test.ts
40 lines (36 loc) · 1.12 KB
/
example.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { api } from "./_generated/api";
import { ConvexTestingHelper } from "convex-helpers/testing";
describe("testingExample", () => {
let t: ConvexTestingHelper;
beforeEach(() => {
t = new ConvexTestingHelper();
});
afterEach(async () => {
await t.mutation(api.testingFunctions.clearAll, {});
await t.close();
});
test("counter", async () => {
expect(await t.query(api.counter.getCounter, { counterName: "foo" })).toBe(
0,
);
expect(() =>
t.query(api.counter.getCounterOrThrow, { counterName: "foo" }),
).rejects.toThrow(/Counter not found/);
expect(() =>
t.query(api.counter.getCounterOrThrow, { counterName: "bar" }),
).rejects.toThrow(/Counter not found/);
await t.mutation(api.counter.incrementCounter, {
counterName: "foo",
increment: 10,
});
expect(
await t.query(api.counter.getCounterOrThrow, { counterName: "foo" }),
).toBe(10);
expect(await t.query(api.counter.getCounter, { counterName: "foo" })).toBe(
10,
);
expect(await t.query(api.counter.getCounter, { counterName: "bar" })).toBe(
0,
);
});
});