@@ -72,7 +72,11 @@ function inspectValue(val) {
72
72
) ;
73
73
}
74
74
75
- function createErrDiff ( actual , expected , operator ) {
75
+ function getErrorMessage ( operator , message ) {
76
+ return message || kReadableOperator [ operator ] ;
77
+ }
78
+
79
+ function createErrDiff ( actual , expected , operator , message = '' ) {
76
80
let other = '' ;
77
81
let res = '' ;
78
82
let end = '' ;
@@ -110,7 +114,7 @@ function createErrDiff(actual, expected, operator) {
110
114
if ( ( typeof actual !== 'object' || actual === null ) &&
111
115
( typeof expected !== 'object' || expected === null ) &&
112
116
( actual !== 0 || expected !== 0 ) ) { // -0 === +0
113
- return `${ kReadableOperator [ operator ] } \n\n` +
117
+ return `${ getErrorMessage ( operator , message ) } \n\n` +
114
118
`${ actualLines [ 0 ] } !== ${ expectedLines [ 0 ] } \n` ;
115
119
}
116
120
} else if ( operator !== 'strictEqualObject' ) {
@@ -184,8 +188,7 @@ function createErrDiff(actual, expected, operator) {
184
188
185
189
let printedLines = 0 ;
186
190
let identical = 0 ;
187
- const msg = kReadableOperator [ operator ] +
188
- `\n${ colors . green } + actual${ colors . white } ${ colors . red } - expected${ colors . white } ` ;
191
+ const msg = `${ getErrorMessage ( operator , message ) } \n${ colors . green } + actual${ colors . white } ${ colors . red } - expected${ colors . white } ` ;
189
192
const skippedMsg = ` ${ colors . blue } ...${ colors . white } Lines skipped` ;
190
193
191
194
let lines = actualLines ;
@@ -337,7 +340,11 @@ class AssertionError extends Error {
337
340
if ( isErrorStackTraceLimitWritable ( ) ) Error . stackTraceLimit = 0 ;
338
341
339
342
if ( message != null ) {
340
- super ( String ( message ) ) ;
343
+ if ( operator === 'deepStrictEqual' || operator === 'strictEqual' ) {
344
+ super ( createErrDiff ( actual , expected , operator , message ) ) ;
345
+ } else {
346
+ super ( String ( message ) ) ;
347
+ }
341
348
} else {
342
349
// Reset colors on each call to make sure we handle dynamically set environment
343
350
// variables correct.
0 commit comments