@@ -95,6 +95,28 @@ Deno.test( 'partialSafeParse', async t => {
9595 )
9696 } )
9797
98+ await t . step ( `Readme Example` , ( ) => {
99+ const userSchema = z . object ( { name : z . string ( ) , age : z . number ( ) } )
100+ const result = zu . partialSafeParse ( userSchema , { name : null , age : 42 } )
101+ assertObjectMatch (
102+ result ,
103+ {
104+ successType : 'partial' ,
105+ validData : { age : 42 } ,
106+ invalidData : { name : null } ,
107+ }
108+ )
109+ assertEquals (
110+ result . error ?. flatten ( ) . fieldErrors ?? { } ,
111+ {
112+ name : [ 'Expected string, received null' ] ,
113+ }
114+ )
115+ } )
116+
117+
118+
119+
98120 // await t.step( `with useURLSearchParams`, () => {
99121 // const params = new URLSearchParams( 'foo=foo&bar=42' )
100122 // const schema = zu.useURLSearchParams(
@@ -122,23 +144,6 @@ Deno.test( 'partialSafeParse', async t => {
122144 // // )
123145 // } )
124146
125- await t . step ( `Readme Example` , ( ) => {
126- const userSchema = z . object ( { name : z . string ( ) , age : z . number ( ) } )
127- const result = zu . partialSafeParse ( userSchema , { name : null , age : 42 } )
128- assertObjectMatch (
129- result ,
130- {
131- successType : 'partial' ,
132- validData : { age : 42 } ,
133- invalidData : { name : null } ,
134- }
135- )
136- assertEquals (
137- result . error ?. flatten ( ) . fieldErrors ?? { } ,
138- {
139- name : [ 'Expected string, received null' ] ,
140- }
141- )
142- } )
147+
143148
144149} )
0 commit comments