File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -143,7 +143,7 @@ export function patchError(Zone: ZoneType): void {
143
143
// We got called with a `new` operator AND we are subclass of ZoneAwareError
144
144
// in that case we have to copy all of our properties to `this`.
145
145
Object . keys ( error )
146
- . concat ( 'stack' , 'message' )
146
+ . concat ( 'stack' , 'message' , 'cause' )
147
147
. forEach ( ( key ) => {
148
148
const value = ( error as any ) [ key ] ;
149
149
if ( value !== undefined ) {
Original file line number Diff line number Diff line change @@ -180,6 +180,21 @@ describe('ZoneAwareError', () => {
180
180
expect ( spy ) . toHaveBeenCalledWith ( 'test' ) ;
181
181
} ) ;
182
182
183
+ it ( 'should copy cause on error that extends native' , ( ) => {
184
+ class WrappedError extends Error {
185
+ constructor ( error : unknown ) {
186
+ super (
187
+ 'wrapped' ,
188
+ // @ts -ignore
189
+ { cause : error } ,
190
+ ) ;
191
+ }
192
+ }
193
+ const cause = new Error ( 'original' ) ;
194
+ const wrapped = new WrappedError ( cause ) as any ;
195
+ expect ( wrapped . cause ) . toBe ( cause ) ;
196
+ } ) ;
197
+
183
198
it ( 'should always have stack property even without throw' , ( ) => {
184
199
// in IE, the stack will be undefined without throw
185
200
// in ZoneAwareError, we will make stack always be
You can’t perform that action at this time.
0 commit comments