File tree 2 files changed +15
-2
lines changed
2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ class ParseError extends Error {
7
7
const errorMessage = options ?. cause
8
8
? `${ message } . This error was caused by: ${ options ?. cause . message } .`
9
9
: message ;
10
- super ( errorMessage ) ;
10
+ super ( errorMessage , options ) ;
11
11
this . name = 'ParseError' ;
12
12
}
13
13
}
Original file line number Diff line number Diff line change 1
- import { z } from 'zod' ;
1
+ /**
2
+ * Test decorator parser
3
+ *
4
+ * @group unit/parser
5
+ */
6
+
7
+ import { z , ZodError } from 'zod' ;
2
8
import { Envelope } from '../../src/envelopes/envelope.js' ;
3
9
import { ParseError } from '../../src/errors.js' ;
4
10
@@ -74,5 +80,12 @@ describe('envelope: ', () => {
74
80
Envelope . parse ( { name : 123 } , z . object ( { name : z . string ( ) } ) )
75
81
) . toThrow ( ) ;
76
82
} ) ;
83
+ it ( 'includes the ZodError as the cause of the ParseError' , ( ) => {
84
+ try {
85
+ Envelope . parse ( '{"name": "John"}' , z . object ( { name : z . number ( ) } ) ) ;
86
+ } catch ( error ) {
87
+ expect ( ( error as Error ) . cause ) . toBeInstanceOf ( ZodError ) ;
88
+ }
89
+ } ) ;
77
90
} ) ;
78
91
} ) ;
You can’t perform that action at this time.
0 commit comments