|
1 | 1 | 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'; |
3 | 3 | import { Foo, bigZodSchema } from './data.js'; |
4 | 4 | import { constraints, type InputConstraints } from '$lib/jsonSchema/constraints.js'; |
5 | 5 | import { defaultValues } from '$lib/jsonSchema/schemaDefaults.js'; |
@@ -879,3 +879,25 @@ describe('Enum validation', () => { |
879 | 879 | }); |
880 | 880 | }); |
881 | 881 | }); |
| 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