File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Top Open diff view settings Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Top Open diff view settings Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ class ParseError extends Error {
77 const errorMessage = options ?. cause
88 ? `${ message } . This error was caused by: ${ options ?. cause . message } .`
99 : message ;
10- super ( errorMessage ) ;
10+ super ( errorMessage , options ) ;
1111 this . name = 'ParseError' ;
1212 }
1313}
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' ;
28import { Envelope } from '../../src/envelopes/envelope.js' ;
39import { ParseError } from '../../src/errors.js' ;
410
@@ -74,5 +80,12 @@ describe('envelope: ', () => {
7480 Envelope . parse ( { name : 123 } , z . object ( { name : z . string ( ) } ) )
7581 ) . toThrow ( ) ;
7682 } ) ;
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+ } ) ;
7790 } ) ;
7891} ) ;
You can’t perform that action at this time.
0 commit comments