Rocky_Mountain_Vending/.pnpm-store/v10/files/1e/a7e8e16e12f1cb906ab798af185353e7b1fc6b230ca2827313e42bb4d64a2ea64d6b5f555824b5323bb73b6e55b64b9273d42763ec0e0e1f97d83f3bd16c62
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

68 lines
1.8 KiB
Text

import { expect, test } from "vitest";
import * as z from "zod/v4";
test("async refine .parse()", async () => {
// throws ZodAsyncError
const s1 = z.string().refine(async (_val) => true);
expect(() => s1.safeParse("asdf")).toThrow();
});
test("async refine", async () => {
const s1 = z.string().refine(async (_val) => true);
const r1 = await s1.parseAsync("asdf");
expect(r1).toEqual("asdf");
const s2 = z.string().refine(async (_val) => false);
const r2 = await s2.safeParseAsync("asdf");
expect(r2.success).toBe(false);
expect(r2).toMatchInlineSnapshot(`
{
"error": [ZodError: [
{
"code": "custom",
"path": [],
"message": "Invalid input"
}
]],
"success": false,
}
`);
});
test("async refine with Promises", async () => {
// expect.assertions(2);
const schema1 = z.string().refine((_val) => Promise.resolve(true));
const v1 = await schema1.parseAsync("asdf");
expect(v1).toEqual("asdf");
const schema2 = z.string().refine((_val) => Promise.resolve(false));
await expect(schema2.parseAsync("asdf")).rejects.toBeDefined();
const schema3 = z.string().refine((_val) => Promise.resolve(true));
await expect(schema3.parseAsync("asdf")).resolves.toEqual("asdf");
return await expect(schema3.parseAsync("qwer")).resolves.toEqual("qwer");
});
test("async refine that uses value", async () => {
const schema1 = z.string().refine(async (val) => {
return val.length > 5;
});
const r1 = await schema1.safeParseAsync("asdf");
expect(r1.success).toBe(false);
expect(r1.error).toMatchInlineSnapshot(`
[ZodError: [
{
"code": "custom",
"path": [],
"message": "Invalid input"
}
]]
`);
const r2 = await schema1.safeParseAsync("asdf123");
expect(r2.success).toBe(true);
expect(r2.data).toEqual("asdf123");
});