/opt/canhelp/node_modules/better-auth/node_modules/zod/src/v4/classic/tests
NameSizeModeActions
anyunknown.test.ts6390644editdlrm
apply.test.ts15090644editdlrm
array.test.ts72480644editdlrm
assignability.test.ts67900644editdlrm
async-parsing.test.ts123110644editdlrm
async-refinements.test.ts18670644editdlrm
base.test.ts1790644editdlrm
bigint.test.ts19560644editdlrm
brand.test.ts35740644editdlrm
catch.test.ts78310644editdlrm
coalesce.test.ts7430644editdlrm
codec-examples.test.ts190300644editdlrm
codec.test.ts188530644editdlrm
coerce.test.ts77360644editdlrm
continuability.test.ts80200644editdlrm
custom.test.ts12150644editdlrm
date.test.ts16710644editdlrm
datetime.test.ts119320644editdlrm
default.test.ts92260644editdlrm
describe-meta-checks.test.ts9650644editdlrm
description.test.ts12940644editdlrm
discriminated-unions.test.ts176650644editdlrm
enum.test.ts84880644editdlrm
error-utils.test.ts137440644editdlrm
error.test.ts195020644editdlrm
file.test.ts26410644editdlrm
firstparty.test.ts30450644editdlrm
fix-json-issue.test.ts7710644editdlrm
from-json-schema.test.ts214980644editdlrm
function.test.ts83440644editdlrm
generics.test.ts21620644editdlrm
hash.test.ts32040644editdlrm
index.test.ts311910644editdlrm
instanceof.test.ts16580644editdlrm
intersection.test.ts55550644editdlrm
json.test.ts33270644editdlrm
lazy.test.ts47560644editdlrm
literal.test.ts30950644editdlrm
map.test.ts76220644editdlrm
nan.test.ts6450644editdlrm
nested-refine.test.ts36230644editdlrm
nonoptional.test.ts28410644editdlrm
nullable.test.ts5910644editdlrm
number.test.ts86440644editdlrm
object.test.ts184810644editdlrm
optional.test.ts73320644editdlrm
partial.test.ts129730644editdlrm
pickomit.test.ts68850644editdlrm
pipe.test.ts23380644editdlrm
prefault.test.ts20630644editdlrm
preprocess.test.ts65220644editdlrm
primitive.test.ts76490644editdlrm
promise.test.ts23240644editdlrm
prototypes.test.ts4980644editdlrm
readonly.test.ts117860644editdlrm
record.test.ts172260644editdlrm
recursive-types.test.ts126930644editdlrm
refine.test.ts156490644editdlrm
registries.test.ts73910644editdlrm
set.test.ts56220644editdlrm
standard-schema.test.ts37700644editdlrm
string-formats.test.ts37000644editdlrm
string.test.ts780690644editdlrm
stringbool.test.ts35360644editdlrm
template-literal.test.ts358940644editdlrm
to-json-schema-methods.test.ts101000644editdlrm
to-json-schema.test.ts786390644editdlrm
transform.test.ts82980644editdlrm
tuple.test.ts55320644editdlrm
union.test.ts59360644editdlrm
url.test.ts4020644editdlrm
validations.test.ts67360644editdlrm
void.test.ts3060644editdlrm
Edit: /opt/canhelp/node_modules/better-auth/node_modules/zod/src/v4/classic/tests/preprocess.test.ts (6522B)
import { expect, expectTypeOf, test } from "vitest"; import * as z from "zod/v4"; test("preprocess", () => { const schema = z.preprocess((data) => [data], z.string().array()); const value = schema.parse("asdf"); expect(value).toEqual(["asdf"]); expectTypeOf<(typeof schema)["_input"]>().toEqualTypeOf(); }); test("async preprocess", async () => { const schema = z.preprocess(async (data) => { return [data]; }, z.string().array()); const value = await schema.safeParseAsync("asdf"); expect(value.data).toEqual(["asdf"]); expect(value).toMatchInlineSnapshot(` { "data": [ "asdf", ], "success": true, } `); }); test("ctx.addIssue accepts string", () => { const schema = z.preprocess((_, ctx) => { ctx.addIssue("bad stuff"); }, z.string()); const result = schema.safeParse("asdf"); expect(result.error!.issues).toHaveLength(1); expect(result).toMatchInlineSnapshot(` { "error": [ZodError: [ { "message": "bad stuff", "code": "custom", "path": [] } ]], "success": false, } `); }); test("preprocess ctx.addIssue with parse", () => { const a = z.preprocess((data, ctx) => { ctx.addIssue({ input: data, code: "custom", message: `${data} is not one of our allowed strings`, }); return data; }, z.string()); const result = a.safeParse("asdf"); // expect(result.error!.toJSON()).toContain("not one of our allowed strings"); expect(result.error!.issues).toHaveLength(1); expect(result).toMatchInlineSnapshot(` { "error": [ZodError: [ { "code": "custom", "message": "asdf is not one of our allowed strings", "path": [] } ]], "success": false, } `); }); test("preprocess ctx.addIssue fatal by default", () => { const schema = z.preprocess((data, ctx) => { ctx.addIssue({ code: "custom", message: `custom error`, }); return data; }, z.string()); const result = schema.safeParse(1234); expect(result.error!.issues).toHaveLength(1); expect(result).toMatchInlineSnapshot(` { "error": [ZodError: [ { "code": "custom", "message": "custom error", "path": [] } ]], "success": false, } `); }); test("preprocess ctx.addIssue fatal true", () => { const schema = z.preprocess((data, ctx) => { ctx.addIssue({ input: data, code: "custom", origin: "custom", message: `custom error`, fatal: true, }); return data; }, z.string()); const result = schema.safeParse(1234); expect(result.error!.issues).toHaveLength(1); expect(result).toMatchInlineSnapshot(` { "error": [ZodError: [ { "code": "custom", "origin": "custom", "message": "custom error", "fatal": true, "path": [] } ]], "success": false, } `); }); test("async preprocess ctx.addIssue with parseAsync", async () => { const schema = z.preprocess(async (data, ctx) => { ctx.addIssue({ input: data, code: "custom", message: `${data} is not one of our allowed strings`, }); return data; }, z.string()); const result = await schema.safeParseAsync("asdf"); expect(result.error!.issues).toHaveLength(1); expect(result).toMatchInlineSnapshot(` { "error": [ZodError: [ { "code": "custom", "message": "asdf is not one of our allowed strings", "path": [] } ]], "success": false, } `); }); test("z.NEVER in preprocess", () => { const foo = z.preprocess((val, ctx) => { if (!val) { ctx.addIssue({ input: val, code: "custom", message: "bad" }); return z.NEVER; } return val; }, z.number()); type foo = z.infer; expectTypeOf().toEqualTypeOf(); const result = foo.safeParse(undefined); expect(result.error!.issues).toHaveLength(1); expect(result).toMatchInlineSnapshot(` { "error": [ZodError: [ { "code": "custom", "message": "bad", "path": [] } ]], "success": false, } `); }); test("preprocess as the second property of object", () => { const schema = z.object({ nonEmptyStr: z.string().min(1), positiveNum: z.preprocess((v) => Number(v), z.number().positive()), }); const result = schema.safeParse({ nonEmptyStr: "", positiveNum: "", }); expect(result.error!.issues).toHaveLength(2); expect(result).toMatchInlineSnapshot(` { "error": [ZodError: [ { "origin": "string", "code": "too_small", "minimum": 1, "inclusive": true, "path": [ "nonEmptyStr" ], "message": "Too small: expected string to have >=1 characters" }, { "origin": "number", "code": "too_small", "minimum": 0, "inclusive": false, "path": [ "positiveNum" ], "message": "Too small: expected number to be >0" } ]], "success": false, } `); }); test("preprocess validates with sibling errors", () => { const schema = z.object({ missing: z.string().refine(() => false), preprocess: z.preprocess((data: any) => data?.trim(), z.string().regex(/ asdf/)), }); const result = schema.safeParse({ preprocess: " asdf" }); expect(result.error!.issues).toHaveLength(2); expect(result).toMatchInlineSnapshot(` { "error": [ZodError: [ { "expected": "string", "code": "invalid_type", "path": [ "missing" ], "message": "Invalid input: expected string, received undefined" }, { "origin": "string", "code": "invalid_format", "format": "regex", "pattern": "/ asdf/", "path": [ "preprocess" ], "message": "Invalid string: must match pattern / asdf/" } ]], "success": false, } `); }); test("perform transform with non-fatal issues", () => { const A = z .string() .refine((_) => false) .min(4) .transform((val) => val.length) .pipe(z.number()) .refine((_) => false); expect(A.safeParse("asdfasdf").error!.issues).toHaveLength(1); expect(A.safeParse("asdfasdf").error).toMatchInlineSnapshot(` [ZodError: [ { "code": "custom", "path": [], "message": "Invalid input" } ]] `); });