@@ -72,7 +72,11 @@ function inspectValue(val) {
7272 ) ;
7373}
7474
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 = '' ) {
7680 let other = '' ;
7781 let res = '' ;
7882 let end = '' ;
@@ -110,7 +114,7 @@ function createErrDiff(actual, expected, operator) {
110114 if ( ( typeof actual !== 'object' || actual === null ) &&
111115 ( typeof expected !== 'object' || expected === null ) &&
112116 ( actual !== 0 || expected !== 0 ) ) { // -0 === +0
113- return `${ kReadableOperator [ operator ] } \n\n` +
117+ return `${ getErrorMessage ( operator , message ) } \n\n` +
114118 `${ actualLines [ 0 ] } !== ${ expectedLines [ 0 ] } \n` ;
115119 }
116120 } else if ( operator !== 'strictEqualObject' ) {
@@ -184,8 +188,7 @@ function createErrDiff(actual, expected, operator) {
184188
185189 let printedLines = 0 ;
186190 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 } ` ;
189192 const skippedMsg = ` ${ colors . blue } ...${ colors . white } Lines skipped` ;
190193
191194 let lines = actualLines ;
@@ -337,7 +340,11 @@ class AssertionError extends Error {
337340 if ( isErrorStackTraceLimitWritable ( ) ) Error . stackTraceLimit = 0 ;
338341
339342 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+ }
341348 } else {
342349 // Reset colors on each call to make sure we handle dynamically set environment
343350 // variables correct.
0 commit comments