@@ -34,7 +34,7 @@ describe("Environment checks", () => {
3434 test ( "discriminated unions are not depicted well" , ( ) => {
3535 expect (
3636 z . toJSONSchema (
37- z . discriminatedUnion ( [
37+ z . discriminatedUnion ( "status" , [
3838 z . object ( { status : z . literal ( "success" ) , data : z . any ( ) } ) ,
3939 z . object ( {
4040 status : z . literal ( "error" ) ,
@@ -50,15 +50,6 @@ describe("Environment checks", () => {
5050 expect ( R . omit ( [ "$schema" ] , json ) ) . toEqual ( { } ) ;
5151 } ) ;
5252
53- test ( "meta overrides, does not merge" , ( ) => {
54- const schema = z
55- . string ( )
56- . meta ( { examples : [ "test" ] } )
57- . meta ( { description : "some" } )
58- . meta ( { title : "last" } ) ;
59- expect ( schema . meta ( ) ) . toMatchSnapshot ( ) ;
60- } ) ;
61-
6253 test ( "circular object schema has no sign of getter in its shape" , ( ) => {
6354 const schema = z . object ( {
6455 name : z . string ( ) ,
@@ -88,6 +79,15 @@ describe("Environment checks", () => {
8879 } ) ;
8980
9081 describe ( "Zod new features" , ( ) => {
82+ test ( "meta() merge, not just overrides" , ( ) => {
83+ const schema = z
84+ . string ( )
85+ . meta ( { examples : [ "test" ] } )
86+ . meta ( { description : "some" } )
87+ . meta ( { title : "last" } ) ;
88+ expect ( schema . meta ( ) ) . toMatchSnapshot ( ) ;
89+ } ) ;
90+
9191 test ( "object shape conveys the keys optionality" , ( ) => {
9292 const schema = z . object ( {
9393 one : z . boolean ( ) ,
@@ -104,16 +104,19 @@ describe("Environment checks", () => {
104104 "three" ,
105105 "four" ,
106106 ] ) ;
107- expect ( schema . _zod . def . shape . one . _zod . optionality ) . toBeUndefined ( ) ;
108- expect ( schema . _zod . def . shape . two . _zod . optionality ) . toBe ( "optional" ) ;
109- expect ( schema . _zod . def . shape . three . _zod . optionality ) . toBe ( "defaulted" ) ;
110- /** @link https://github.com/colinhacks/zod/issues/4322 */
111- expect ( schema . _zod . def . shape . four . _zod . optionality ) . not . toBe ( "optional" ) ; // <— undefined
107+ expect ( schema . _zod . def . shape . one . _zod . optin ) . toBeUndefined ( ) ;
108+ expect ( schema . _zod . def . shape . one . _zod . optout ) . toBeUndefined ( ) ;
109+ expect ( schema . _zod . def . shape . two . _zod . optin ) . toBe ( "optional" ) ;
110+ expect ( schema . _zod . def . shape . two . _zod . optout ) . toBe ( "optional" ) ;
111+ expect ( schema . _zod . def . shape . three . _zod . optin ) . toBe ( "optional" ) ;
112+ expect ( schema . _zod . def . shape . three . _zod . optout ) . toBe ( undefined ) ;
113+ expect ( schema . _zod . def . shape . four . _zod . optin ) . toBe ( "optional" ) ;
114+ expect ( schema . _zod . def . shape . four . _zod . optout ) . toBe ( undefined ) ;
112115 expectTypeOf < z . input < typeof schema > > ( ) . toEqualTypeOf < {
113116 one : boolean ;
114117 two ?: boolean | undefined ;
115118 three ?: boolean | undefined ;
116- four : boolean | undefined ;
119+ four ? : boolean | undefined ;
117120 } > ( ) ;
118121 expectTypeOf < z . output < typeof schema > > ( ) . toEqualTypeOf < {
119122 one : boolean ;
0 commit comments