Skip to content

Commit e1c551c

Browse files
committed
Update hook.zod.test.ts for strict validation behavior
1 parent 265ca60 commit e1c551c

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { z } from 'zod';
2+
3+
describe('Hook Validations', () => {
4+
it('should pass for valid input', () => {
5+
const schema = z.object({
6+
name: z.string().min(1),
7+
age: z.number().min(0),
8+
});
9+
const input = { name: 'John Doe', age: 30 };
10+
const parsed = schema.safeParse(input);
11+
expect(parsed.success).toBe(true);
12+
});
13+
14+
it('should fail for missing name', () => {
15+
const schema = z.object({
16+
name: z.string().min(1),
17+
age: z.number().min(0),
18+
});
19+
const input = { age: 30 };
20+
const parsed = schema.safeParse(input);
21+
expect(parsed.success).toBe(false);
22+
expect(parsed.error).toBeDefined();
23+
});
24+
25+
it('should fail for empty name', () => {
26+
const schema = z.object({
27+
name: z.string().min(1),
28+
age: z.number().min(0),
29+
});
30+
const input = { name: '', age: 30 };
31+
const parsed = schema.safeParse(input);
32+
expect(parsed.success).toBe(false);
33+
expect(parsed.error).toBeDefined();
34+
});
35+
36+
it('should fail for negative age', () => {
37+
const schema = z.object({
38+
name: z.string().min(1),
39+
age: z.number().min(0),
40+
});
41+
const input = { name: 'John Doe', age: -5 };
42+
const parsed = schema.safeParse(input);
43+
expect(parsed.success).toBe(false);
44+
expect(parsed.error).toBeDefined();
45+
});
46+
});

0 commit comments

Comments
 (0)