@@ -357,7 +357,6 @@ describe('Formatters', () => {
357357 } ,
358358 {
359359 error : new AssertionError ( {
360- message : 'Expected values to be strictly equal' ,
361360 actual : 1 ,
362361 expected : 2 ,
363362 operator : 'strictEqual' ,
@@ -369,6 +368,11 @@ describe('Formatters', () => {
369368 ) ,
370369 message : expect . stringMatching ( / E x p e c t e d v a l u e s t o b e s t r i c t l y e q u a l / ) ,
371370 cause : undefined ,
371+ actual : 1 ,
372+ expected : 2 ,
373+ operator : 'strictEqual' ,
374+ code : 'ERR_ASSERTION' ,
375+ generatedMessage : true ,
372376 } ,
373377 } ,
374378 {
@@ -432,16 +436,65 @@ describe('Formatters', () => {
432436 cause : 'bar' ,
433437 } ,
434438 } ,
435- ] ) ( 'formats errors correctly ($name)' , ( { error, name, expectedFields } ) => {
439+ ] ) (
440+ 'formats standard errors correctly ($name)' ,
441+ ( { error, name, expectedFields } ) => {
442+ // Act
443+ const formattedError = formatter . formatError ( error ) ;
444+
445+ // Assess
446+ expect ( formattedError ) . toEqual ( {
447+ location : expect . stringMatching ( fileNameRegexp ) ,
448+ stack : expect . stringMatching ( fileNameRegexpWithLine ) ,
449+ name,
450+ ...expectedFields ,
451+ } ) ;
452+ }
453+ ) ;
454+
455+ it ( 'formats custom errors by including only enumerable properties' , ( ) => {
456+ // Prepare
457+ const customSymbol = Symbol ( 'customSymbol' ) ;
458+ class CustomError extends Error {
459+ public otherProperty : string ;
460+
461+ public constructor (
462+ message : string ,
463+ public readonly code : number
464+ ) {
465+ super ( message ) ;
466+ this . name = 'CustomError' ;
467+ this . otherProperty = 'otherProperty' ;
468+ }
469+
470+ public [ customSymbol ] = ( ) : void => {
471+ // do nothing
472+ } ;
473+ }
474+
475+ class SuperCustomError extends CustomError {
476+ public extraProperty : string ;
477+ public constructor ( message : string , code : number ) {
478+ super ( message , code ) ;
479+ this . name = 'SuperCustomError' ;
480+ this . extraProperty = 'extraProperty' ;
481+ }
482+ }
483+
436484 // Act
437- const formattedError = formatter . formatError ( error ) ;
485+ const formattedError = formatter . formatError (
486+ new SuperCustomError ( 'Something went wrong' , 500 )
487+ ) ;
438488
439489 // Assess
440490 expect ( formattedError ) . toEqual ( {
441491 location : expect . stringMatching ( fileNameRegexp ) ,
442492 stack : expect . stringMatching ( fileNameRegexpWithLine ) ,
443- name,
444- ...expectedFields ,
493+ name : 'SuperCustomError' ,
494+ message : 'Something went wrong' ,
495+ code : 500 ,
496+ otherProperty : 'otherProperty' ,
497+ extraProperty : 'extraProperty' ,
445498 } ) ;
446499 } ) ;
447500
0 commit comments