@@ -17,19 +17,18 @@ const kReadableOperator = {
17
17
strictEqual : 'Expected values to be strictly equal:' ,
18
18
strictEqualObject : 'Expected "actual" to be reference-equal to "expected":' ,
19
19
deepEqual : 'Expected values to be loosely deep-equal:' ,
20
- equal : 'Expected values to be loosely equal:' ,
21
20
notDeepStrictEqual : 'Expected "actual" not to be strictly deep-equal to:' ,
22
21
notStrictEqual : 'Expected "actual" to be strictly unequal to:' ,
23
22
notStrictEqualObject :
24
23
'Expected "actual" not to be reference-equal to "expected":' ,
25
24
notDeepEqual : 'Expected "actual" not to be loosely deep-equal to:' ,
26
- notEqual : 'Expected "actual" to be loosely unequal to:' ,
27
25
notIdentical : 'Values identical but not reference-equal:' ,
26
+ notDeepEqualUnequal : 'Expected values not to be loosely deep-equal:'
28
27
} ;
29
28
30
29
// Comparing short primitives should just show === / !== instead of using the
31
30
// diff.
32
- const kMaxShortLength = 10 ;
31
+ const kMaxShortLength = 12 ;
33
32
34
33
function copyError ( source ) {
35
34
const keys = Object . keys ( source ) ;
@@ -81,13 +80,12 @@ function createErrDiff(actual, expected, operator) {
81
80
let i = 0 ;
82
81
let indicator = '' ;
83
82
84
- // In case both values are objects explicitly mark them as not reference equal
85
- // for the `strictEqual` operator.
83
+ // In case both values are objects or functions explicitly mark them as not
84
+ // reference equal for the `strictEqual` operator.
86
85
if ( operator === 'strictEqual' &&
87
- typeof actual === 'object' &&
88
- typeof expected === 'object' &&
89
- actual !== null &&
90
- expected !== null ) {
86
+ ( ( typeof actual === 'object' && actual !== null &&
87
+ typeof expected === 'object' && expected !== null ) ||
88
+ ( typeof actual === 'function' && typeof expected === 'function' ) ) ) {
91
89
operator = 'strictEqualObject' ;
92
90
}
93
91
@@ -153,9 +151,9 @@ function createErrDiff(actual, expected, operator) {
153
151
154
152
// Only remove lines in case it makes sense to collapse those.
155
153
// TODO: Accept env to always show the full error.
156
- if ( actualLines . length > 30 ) {
157
- actualLines [ 26 ] = `${ blue } ...${ white } ` ;
158
- while ( actualLines . length > 27 ) {
154
+ if ( actualLines . length > 50 ) {
155
+ actualLines [ 46 ] = `${ blue } ...${ white } ` ;
156
+ while ( actualLines . length > 47 ) {
159
157
actualLines . pop ( ) ;
160
158
}
161
159
}
@@ -282,8 +280,8 @@ function createErrDiff(actual, expected, operator) {
282
280
}
283
281
}
284
282
}
285
- // Inspected object to big (Show ~20 rows max)
286
- if ( printedLines > 20 && i < maxLines - 2 ) {
283
+ // Inspected object to big (Show ~50 rows max)
284
+ if ( printedLines > 50 && i < maxLines - 2 ) {
287
285
return `${ msg } ${ skippedMsg } \n${ res } \n${ blue } ...${ white } ${ other } \n` +
288
286
`${ blue } ...${ white } ` ;
289
287
}
@@ -348,52 +346,61 @@ class AssertionError extends Error {
348
346
let base = kReadableOperator [ operator ] ;
349
347
const res = inspectValue ( actual ) . split ( '\n' ) ;
350
348
351
- // In case "actual" is an object, it should not be reference equal.
349
+ // In case "actual" is an object or a function, it should not be
350
+ // reference equal.
352
351
if ( operator === 'notStrictEqual' &&
353
- typeof actual === 'object' &&
354
- actual !== null ) {
352
+ ( typeof actual === 'object' && actual !== null ||
353
+ typeof actual === 'function' ) ) {
355
354
base = kReadableOperator . notStrictEqualObject ;
356
355
}
357
356
358
357
// Only remove lines in case it makes sense to collapse those.
359
358
// TODO: Accept env to always show the full error.
360
- if ( res . length > 30 ) {
361
- res [ 26 ] = `${ blue } ...${ white } ` ;
362
- while ( res . length > 27 ) {
359
+ if ( res . length > 50 ) {
360
+ res [ 46 ] = `${ blue } ...${ white } ` ;
361
+ while ( res . length > 47 ) {
363
362
res . pop ( ) ;
364
363
}
365
364
}
366
365
367
366
// Only print a single input.
368
367
if ( res . length === 1 ) {
369
- super ( `${ base } ${ res [ 0 ] } ` ) ;
368
+ super ( `${ base } ${ res [ 0 ] . length > 5 ? '\n\n' : ' ' } ${ res [ 0 ] } ` ) ;
370
369
} else {
371
370
super ( `${ base } \n\n${ res . join ( '\n' ) } \n` ) ;
372
371
}
373
372
} else {
374
373
let res = inspectValue ( actual ) ;
375
- let other = '' ;
374
+ let other = inspectValue ( expected ) ;
376
375
const knownOperators = kReadableOperator [ operator ] ;
377
- if ( operator === 'notDeepEqual' || operator === 'notEqual' ) {
378
- res = `${ kReadableOperator [ operator ] } \n\n${ res } ` ;
376
+ if ( ( operator === 'notDeepEqual' || operator === 'notEqual' ) &&
377
+ res === other ) {
378
+ res = `${ knownOperators } \n\n${ res } ` ;
379
379
if ( res . length > 1024 ) {
380
380
res = `${ res . slice ( 0 , 1021 ) } ...` ;
381
381
}
382
+ super ( res ) ;
382
383
} else {
383
- other = `${ inspectValue ( expected ) } ` ;
384
384
if ( res . length > 512 ) {
385
385
res = `${ res . slice ( 0 , 509 ) } ...` ;
386
386
}
387
387
if ( other . length > 512 ) {
388
388
other = `${ other . slice ( 0 , 509 ) } ...` ;
389
389
}
390
390
if ( operator === 'deepEqual' || operator === 'equal' ) {
391
- res = `${ knownOperators } \n\n${ res } \n\nshould equal\n\n` ;
391
+ const eq = operator === 'deepEqual' ? 'deep-equal' : 'equal' ;
392
+ res = `${ knownOperators } \n\n${ res } \n\nshould loosely ${ eq } \n\n` ;
392
393
} else {
393
- other = ` ${ operator } ${ other } ` ;
394
+ const newOperator = kReadableOperator [ `${ operator } Unequal` ] ;
395
+ if ( newOperator ) {
396
+ const eq = operator === 'notDeepEqual' ? 'deep-equal' : 'equal' ;
397
+ res = `${ newOperator } \n\n${ res } \n\nshould not loosely ${ eq } \n\n` ;
398
+ } else {
399
+ other = ` ${ operator } ${ other } ` ;
400
+ }
394
401
}
402
+ super ( `${ res } ${ other } ` ) ;
395
403
}
396
- super ( `${ res } ${ other } ` ) ;
397
404
}
398
405
}
399
406
0 commit comments