Skip to content

Commit 79f82f9

Browse files
committed
Added test for custom superValidate
1 parent 7d7729e commit 79f82f9

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/tests/superValidate.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect, assert, beforeEach } from 'vitest';
2-
import type { ValidationAdapter } from '$lib/adapters/index.js';
2+
import type { Infer, InferIn, ValidationAdapter } from '$lib/adapters/index.js';
33
import { Foo, bigZodSchema } from './data.js';
44
import { constraints, type InputConstraints } from '$lib/jsonSchema/constraints.js';
55
import { defaultValues } from '$lib/jsonSchema/schemaDefaults.js';
@@ -879,3 +879,25 @@ describe('Enum validation', () => {
879879
});
880880
});
881881
});
882+
883+
describe('Customized superValidate', () => {
884+
type SuperParams<T extends Record<string, unknown>> = Parameters<typeof superValidate<T>>;
885+
type ZodSchema = Parameters<typeof zod>[0];
886+
887+
function zodValidate<T extends ZodSchema, M>(
888+
data: SuperParams<InferIn<T>>[0],
889+
schema: T,
890+
options?: SuperParams<Infer<T>>[2]
891+
) {
892+
return superValidate<Infer<T>, M, InferIn<T>>(data, zod(schema), options);
893+
}
894+
895+
const zodSchema = z.object({
896+
num: z.number().int()
897+
});
898+
899+
it('Should be type-safe', async () => {
900+
const v = await zodValidate(null, zodSchema);
901+
expect(v.data.num).toBe(0);
902+
});
903+
});

0 commit comments

Comments
 (0)