@@ -72,27 +72,62 @@ describe('isZodTypeLike', () => {
7272} ) ;
7373
7474describe ( 'isZodType' , ( ) => {
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' ) ;
75+ describe ( 'v3' , ( ) => {
76+ // since we use require here, the prototype chain in the cjs module will be different than the esm build
77+ const { z : z3_2 } = require ( 'zod/v3' ) as typeof import ( 'zod/v3' ) ;
7778
78- it ( 'should return true for an instance of ZodNumber' , ( ) => {
79- expect ( isZodType ( z3 . number ( ) , { version : 3 } ) ) . toBe ( true ) ;
79+ it ( 'should return true for an instance of ZodNumber' , ( ) => {
80+ expect ( isZodType ( z3 . number ( ) , { version : 3 } ) ) . toBe ( true ) ;
81+ } ) ;
82+ it ( 'should return true for an instance of ZodObject' , ( ) => {
83+ expect ( isZodType ( z3 . object ( { } ) , { version : 3 } ) ) . toBe ( true ) ;
84+ } ) ;
85+ it ( 'should return false for null' , ( ) => {
86+ expect ( isZodType ( null , { version : 3 } ) ) . toBe ( false ) ;
87+ } ) ;
88+ it ( 'should return false for any empty object' , ( ) => {
89+ expect ( isZodType ( { } , { version : 3 } ) ) . toBe ( false ) ;
90+ } ) ;
91+ it ( 'should return false for an object with a null prototype' , ( ) => {
92+ expect ( isZodType ( Object . create ( null ) , { version : 3 } ) ) . toBe ( false ) ;
93+ } ) ;
94+ it ( 'should return false for a Zod v4 object' , ( ) => {
95+ expect ( isZodType ( z4 . object ( { } ) , { version : 3 } ) ) . toBe ( false ) ;
96+ } ) ;
97+ it ( 'should return true for a ZodObject created in a different context' , ( ) => {
98+ const input = z3_2 . object ( { } ) ;
99+ expect ( input ) . not . toBeInstanceOf ( z3 . ZodType ) ;
100+ expect ( isZodType ( input , { version : 3 } ) ) . toBe ( true ) ;
101+ } ) ;
80102 } ) ;
81- it ( 'should return true for an instance of ZodObject' , ( ) => {
82- expect ( isZodType ( z3 . object ( { } ) , { version : 3 } ) ) . toBe ( true ) ;
83- } ) ;
84- it ( 'should return false for null' , ( ) => {
85- expect ( isZodType ( null , { version : 3 } ) ) . toBe ( false ) ;
86- } ) ;
87- it ( 'should return false for any empty object' , ( ) => {
88- expect ( isZodType ( { } , { version : 3 } ) ) . toBe ( false ) ;
89- } ) ;
90- it ( 'should return false for an object with a null prototype' , ( ) => {
91- expect ( isZodType ( Object . create ( null ) , { version : 3 } ) ) . 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 ( isZodType ( input , { version : 3 } ) ) . toBe ( true ) ;
103+ describe ( 'v4' , ( ) => {
104+ it ( 'should return true for an instance of ZodNumber' , ( ) => {
105+ expect ( isZodType ( z4 . number ( ) , { version : 4 } ) ) . toBe ( true ) ;
106+ } ) ;
107+ it ( 'should return true for an instance of ZodObject' , ( ) => {
108+ expect ( isZodType ( z4 . object ( { } ) , { version : 4 } ) ) . toBe ( true ) ;
109+ } ) ;
110+ it ( 'should return false for null' , ( ) => {
111+ expect ( isZodType ( null , { version : 4 } ) ) . toBe ( false ) ;
112+ } ) ;
113+ it ( 'should return false for any empty object' , ( ) => {
114+ expect ( isZodType ( { } , { version : 4 } ) ) . toBe ( false ) ;
115+ } ) ;
116+ it ( 'should return false for a Zod v3 object' , ( ) => {
117+ expect ( isZodType ( z3 . object ( { } ) , { version : 4 } ) ) . toBe ( false ) ;
118+ } ) ;
119+ it ( 'should return true for a ZodObject created in a different context' , ( ) => {
120+ const base = z4 . object ( { } ) ;
121+ const input = {
122+ _zod : {
123+ version : structuredClone ( base . _zod . version )
124+ } ,
125+ '~standard' : {
126+ vendor : base [ '~standard' ] . vendor
127+ }
128+ } ;
129+ expect ( input ) . not . toBeInstanceOf ( z4 . ZodType ) ;
130+ expect ( isZodType ( input , { version : 4 } ) ) . toBe ( true ) ;
131+ } ) ;
97132 } ) ;
98133} ) ;
0 commit comments