File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -101,15 +101,27 @@ describe("Environment checks", () => {
101101 } ) ;
102102
103103 describe ( "Zod new features" , ( ) => {
104- test ( "retention: object shape conveys the keys optionality" , ( ) => {
104+ test ( "object shape conveys the keys optionality" , ( ) => {
105105 const schema = z . object ( {
106106 one : z . boolean ( ) ,
107107 two : z . boolean ( ) . optional ( ) ,
108+ three : z . boolean ( ) . default ( true ) ,
109+ four : z
110+ . boolean ( )
111+ . optional ( )
112+ . transform ( ( ) => false ) ,
108113 } ) ;
109- expect ( Object . keys ( schema . _zod . def . shape ) ) . toEqual ( [ "one" , "two" ] ) ;
110- expect ( schema . _zod . def . shape . one ) . toBeInstanceOf ( z . ZodBoolean ) ;
111- expect ( schema . _zod . def . shape . two ) . toBeInstanceOf ( z . ZodOptional ) ;
112- expect ( schema . _zod . def . shape . two . isOptional ( ) ) . toBe ( true ) ;
114+ expect ( Object . keys ( schema . _zod . def . shape ) ) . toEqual ( [
115+ "one" ,
116+ "two" ,
117+ "three" ,
118+ "four" ,
119+ ] ) ;
120+ expect ( schema . _zod . def . shape . one . _zod . optionality ) . toBeUndefined ( ) ;
121+ expect ( schema . _zod . def . shape . two . _zod . optionality ) . toBe ( "optional" ) ;
122+ expect ( schema . _zod . def . shape . three . _zod . optionality ) . toBe ( "defaulted" ) ;
123+ /** @link https://github.com/colinhacks/zod/issues/4322 */
124+ expect ( schema . _zod . def . shape . four . _zod . optionality ) . not . toBe ( "optional" ) ; // <— undefined
113125 } ) ;
114126
115127 test ( "coerce is safe for nullable and optional" , ( ) => {
You can’t perform that action at this time.
0 commit comments