|
| 1 | +/* eslint-disable @typescript-eslint/no-require-imports */ |
1 | 2 | import { describe, expect, expectTypeOf, it, test } from 'vitest'; |
2 | 3 | import { z as z3 } from 'zod/v3'; |
3 | 4 | import { z as z4 } from 'zod/v4'; |
4 | 5 |
|
5 | | -import { isZodTypeLike } from '../zod4.js'; |
| 6 | +import { isZodTypeLike, isZodV3Type } from '../zod4.js'; |
6 | 7 |
|
7 | 8 | import type { |
8 | 9 | ZodErrorLike, |
@@ -69,3 +70,29 @@ describe('isZodTypeLike', () => { |
69 | 70 | expect(isZodTypeLike({ '~standard': { vendor: 'DNP' } })).toBe(false); |
70 | 71 | }); |
71 | 72 | }); |
| 73 | + |
| 74 | +describe('isZodV3Type', () => { |
| 75 | + // since we use require here, the prototype chain in the cjs module will be different than the esm build |
| 76 | + const { z: z3_2 } = require('zod/v3') as typeof import('zod/v3'); |
| 77 | + |
| 78 | + it('should return true for an instance of ZodNumber', () => { |
| 79 | + expect(isZodV3Type(z3.number())).toBe(true); |
| 80 | + }); |
| 81 | + it('should return true for an instance of ZodObject', () => { |
| 82 | + expect(isZodV3Type(z3.object({}))).toBe(true); |
| 83 | + }); |
| 84 | + it('should return false for null', () => { |
| 85 | + expect(isZodV3Type(null)).toBe(false); |
| 86 | + }); |
| 87 | + it('should return false for any empty object', () => { |
| 88 | + expect(isZodV3Type({})).toBe(false); |
| 89 | + }); |
| 90 | + it('should return false for an object with a null prototype', () => { |
| 91 | + expect(isZodV3Type(Object.create(null))).toBe(false); |
| 92 | + }); |
| 93 | + it('should return true for a ZodObject created in a different context', () => { |
| 94 | + const input = z3_2.object({}); |
| 95 | + expect(input).not.toBeInstanceOf(z3.ZodType); |
| 96 | + expect(isZodV3Type(input)).toBe(true); |
| 97 | + }); |
| 98 | +}); |
0 commit comments