|
1 | | -import { expectTypeOf, test } from 'vitest'; |
2 | | -import type { z as z3 } from 'zod/v3'; |
3 | | -import type { z as z4 } from 'zod/v4'; |
| 1 | +import { describe, expect, expectTypeOf, it, test } from 'vitest'; |
| 2 | +import { z as z3 } from 'zod/v3'; |
| 3 | +import { z as z4 } from 'zod/v4'; |
| 4 | + |
| 5 | +import { isZodTypeLike } from '../zod4.js'; |
4 | 6 |
|
5 | 7 | import type { |
6 | 8 | ZodErrorLike, |
@@ -48,3 +50,22 @@ test('ZodTypeLike', () => { |
48 | 50 | expectTypeOf<z4.ZodNumber>().toMatchTypeOf<ZodTypeLike<number>>(); |
49 | 51 | expectTypeOf<z4.ZodNumber>().not.toMatchTypeOf<ZodTypeLike<string>>(); |
50 | 52 | }); |
| 53 | + |
| 54 | +describe('isZodTypeLike', () => { |
| 55 | + it('should return true for Zod v3 types', () => { |
| 56 | + expect(isZodTypeLike(z3.object({}))).toBe(true); |
| 57 | + expect(isZodTypeLike(z3.number())).toBe(true); |
| 58 | + expect(isZodTypeLike(z3.any())).toBe(true); |
| 59 | + }); |
| 60 | + it('should return true for Zod v4 types', () => { |
| 61 | + expect(isZodTypeLike(z4.object({}))).toBe(true); |
| 62 | + expect(isZodTypeLike(z4.number())).toBe(true); |
| 63 | + expect(isZodTypeLike(z4.any())).toBe(true); |
| 64 | + }); |
| 65 | + it('should return false for an object without a standard schema', () => { |
| 66 | + expect(isZodTypeLike({})).toBe(false); |
| 67 | + }); |
| 68 | + it('should return false for an object with a standard schema, but the incorrect vendor name', () => { |
| 69 | + expect(isZodTypeLike({ '~standard': { vendor: 'DNP' } })).toBe(false); |
| 70 | + }); |
| 71 | +}); |
0 commit comments