File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -6,14 +6,14 @@ class ErrorWithCause extends Error { // linemod-prefix-with: export
66 * @param {string } message
77 * @param {{ cause?: T } } [options]
88 */
9- constructor ( message , { cause } = { } ) {
9+ constructor ( message , options ) {
1010 super ( message ) ;
1111
1212 /** @type {string } */
1313 this . name = ErrorWithCause . name ;
14- if ( cause ) {
15- /** @type {T } */
16- this . cause = cause ;
14+ if ( options && Object . prototype . hasOwnProperty . call ( options , ' cause' ) ) {
15+ /** @type {T|undefined } */
16+ this . cause = options . cause ;
1717 }
1818 /** @type {string } */
1919 this . message = message ;
Original file line number Diff line number Diff line change @@ -37,4 +37,17 @@ describe('ErrorWithCause', () => {
3737 const err = new ErrorWithCause ( 'Foo' ) ;
3838 err . should . have . property ( 'stack' ) . that . is . a ( 'string' ) . which . startsWith ( 'ErrorWithCause: Foo\n' ) ;
3939 } ) ;
40+
41+ it ( 'should set cause property when given undefined cause' , ( ) => {
42+ ( new ErrorWithCause ( 'Foo' , { cause : undefined } ) ) . should . have . property ( 'cause' , undefined ) ;
43+ } ) ;
44+
45+ it ( 'should set cause property when given null cause' , ( ) => {
46+ // eslint-disable-next-line unicorn/no-null
47+ ( new ErrorWithCause ( 'Foo' , { cause : null } ) ) . should . have . property ( 'cause' , null ) ;
48+ } ) ;
49+
50+ it ( 'should set cause property when given false cause' , ( ) => {
51+ ( new ErrorWithCause ( 'Foo' , { cause : false } ) ) . should . have . property ( 'cause' , false ) ;
52+ } ) ;
4053} ) ;
You can’t perform that action at this time.
0 commit comments