@@ -328,25 +328,28 @@ describe("zod-to-ts", () => {
328328 ) ;
329329 } ) ;
330330
331- describe ( "PrimitiveSchema" , ( ) => {
332- const primitiveSchema = z . object ( {
333- string : z . string ( ) ,
334- number : z . number ( ) ,
335- boolean : z . boolean ( ) ,
336- date : z . date ( ) ,
337- undefined : z . undefined ( ) ,
338- null : z . null ( ) ,
339- void : z . void ( ) ,
340- any : z . any ( ) ,
341- unknown : z . unknown ( ) ,
342- never : z . never ( ) ,
343- } ) ;
344- const node = zodToTs ( primitiveSchema , { ctx } ) ;
331+ describe . each ( [ true , false ] ) (
332+ "PrimitiveSchema (isResponse=%s)" ,
333+ ( isResponse ) => {
334+ const primitiveSchema = z . object ( {
335+ string : z . string ( ) ,
336+ number : z . number ( ) ,
337+ boolean : z . boolean ( ) ,
338+ date : z . date ( ) ,
339+ undefined : z . undefined ( ) ,
340+ null : z . null ( ) ,
341+ void : z . void ( ) ,
342+ any : z . any ( ) ,
343+ unknown : z . unknown ( ) ,
344+ never : z . never ( ) ,
345+ } ) ;
346+ const node = zodToTs ( primitiveSchema , { ctx : { ...ctx , isResponse } } ) ;
345347
346- test ( "outputs correct typescript" , ( ) => {
347- expect ( printNodeTest ( node ) ) . toMatchSnapshot ( ) ;
348- } ) ;
349- } ) ;
348+ test ( "outputs correct typescript" , ( ) => {
349+ expect ( printNodeTest ( node ) ) . toMatchSnapshot ( ) ;
350+ } ) ;
351+ } ,
352+ ) ;
350353
351354 describe ( "z.discriminatedUnion()" , ( ) => {
352355 const shapeSchema = z . discriminatedUnion ( "kind" , [
@@ -392,6 +395,13 @@ describe("zod-to-ts", () => {
392395 ) . toMatchSnapshot ( ) ;
393396 } ) ;
394397
398+ test ( "should handle preprocess error in request" , ( ) => {
399+ const schema = z . preprocess ( ( ) => {
400+ throw new Error ( "intentional" ) ;
401+ } , z . number ( ) ) ;
402+ expect ( printNodeTest ( zodToTs ( schema , { ctx } ) ) ) . toMatchSnapshot ( ) ;
403+ } ) ;
404+
395405 test ( "should handle an error within the transformation" , ( ) => {
396406 const schema = z
397407 . number ( )
0 commit comments