@@ -357,7 +357,6 @@ describe('Formatters', () => {
357
357
} ,
358
358
{
359
359
error : new AssertionError ( {
360
- message : 'Expected values to be strictly equal' ,
361
360
actual : 1 ,
362
361
expected : 2 ,
363
362
operator : 'strictEqual' ,
@@ -369,6 +368,11 @@ describe('Formatters', () => {
369
368
) ,
370
369
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 / ) ,
371
370
cause : undefined ,
371
+ actual : 1 ,
372
+ expected : 2 ,
373
+ operator : 'strictEqual' ,
374
+ code : 'ERR_ASSERTION' ,
375
+ generatedMessage : true ,
372
376
} ,
373
377
} ,
374
378
{
@@ -432,16 +436,65 @@ describe('Formatters', () => {
432
436
cause : 'bar' ,
433
437
} ,
434
438
} ,
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
+
436
484
// Act
437
- const formattedError = formatter . formatError ( error ) ;
485
+ const formattedError = formatter . formatError (
486
+ new SuperCustomError ( 'Something went wrong' , 500 )
487
+ ) ;
438
488
439
489
// Assess
440
490
expect ( formattedError ) . toEqual ( {
441
491
location : expect . stringMatching ( fileNameRegexp ) ,
442
492
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' ,
445
498
} ) ;
446
499
} ) ;
447
500
0 commit comments