File tree 2 files changed +10
-0
lines changed
packages/zod-mock/src/lib
2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ describe('zod-mock', () => {
32
32
z . object ( { discriminator : z . literal ( 'a' ) , a : z . boolean ( ) } ) ,
33
33
z . object ( { discriminator : z . literal ( 'b' ) , b : z . string ( ) } ) ,
34
34
] ) ,
35
+ readonly : z . boolean ( ) . readonly ( ) ,
35
36
} ) ;
36
37
37
38
const mockData = generateMock ( schema ) ;
@@ -58,6 +59,7 @@ describe('zod-mock', () => {
58
59
expect ( mockData . set ) . toBeTruthy ( ) ;
59
60
expect ( mockData . map ) . toBeTruthy ( ) ;
60
61
expect ( mockData . discriminatedUnion ) . toBeTruthy ( ) ;
62
+ expect ( typeof mockData . readonly ) . toEqual ( 'boolean' ) ;
61
63
} ) ;
62
64
63
65
it ( 'should generate mock data of the appropriate type when the field names overlap Faker properties that are not valid functions' , ( ) => {
Original file line number Diff line number Diff line change @@ -536,6 +536,13 @@ function parseLazy(
536
536
return generateMock ( zodRef . _def . getter ( ) , options ) ;
537
537
}
538
538
539
+ function parseReadonly (
540
+ zodRef : z . ZodReadonly < ZodTypeAny > ,
541
+ options ?: GenerateMockOptions
542
+ ) {
543
+ return generateMock ( zodRef . _def . innerType , options ) ;
544
+ }
545
+
539
546
const workerMap = {
540
547
ZodObject : parseObject ,
541
548
ZodRecord : parseRecord ,
@@ -565,6 +572,7 @@ const workerMap = {
565
572
ZodBranded : parseBranded ,
566
573
ZodNull : ( ) => null ,
567
574
ZodNaN : ( ) => NaN ,
575
+ ZodReadonly : parseReadonly ,
568
576
} ;
569
577
570
578
type WorkerKeys = keyof typeof workerMap ;
You can’t perform that action at this time.
0 commit comments