@@ -17,19 +17,18 @@ const kReadableOperator = {
1717 strictEqual: 'Expected values to be strictly equal:',
1818 strictEqualObject: 'Expected "actual" to be reference-equal to "expected":',
1919 deepEqual: 'Expected values to be loosely deep-equal:',
20- equal: 'Expected values to be loosely equal:',
2120 notDeepStrictEqual: 'Expected "actual" not to be strictly deep-equal to:',
2221 notStrictEqual: 'Expected "actual" to be strictly unequal to:',
2322 notStrictEqualObject:
2423 'Expected "actual" not to be reference-equal to "expected":',
2524 notDeepEqual: 'Expected "actual" not to be loosely deep-equal to:',
26- notEqual: 'Expected "actual" to be loosely unequal to:',
2725 notIdentical: 'Values identical but not reference-equal:',
26+ notDeepEqualUnequal: 'Expected values not to be loosely deep-equal:'
2827};
2928
3029// Comparing short primitives should just show === / !== instead of using the
3130// diff.
32- const kMaxShortLength = 10 ;
31+ const kMaxShortLength = 12 ;
3332
3433function copyError(source) {
3534 const keys = Object.keys(source);
@@ -81,13 +80,12 @@ function createErrDiff(actual, expected, operator) {
8180 let i = 0;
8281 let indicator = '';
8382
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.
8685 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'))) {
9189 operator = 'strictEqualObject';
9290 }
9391
@@ -153,9 +151,9 @@ function createErrDiff(actual, expected, operator) {
153151
154152 // Only remove lines in case it makes sense to collapse those.
155153 // 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 ) {
159157 actualLines.pop();
160158 }
161159 }
@@ -282,8 +280,8 @@ function createErrDiff(actual, expected, operator) {
282280 }
283281 }
284282 }
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) {
287285 return `${msg}${skippedMsg}\n${res}\n${blue}...${white}${other}\n` +
288286 `${blue}...${white}`;
289287 }
@@ -348,52 +346,61 @@ class AssertionError extends Error {
348346 let base = kReadableOperator[operator];
349347 const res = inspectValue(actual).split('\n');
350348
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.
352351 if (operator === 'notStrictEqual' &&
353- typeof actual === 'object' &&
354- actual !== null ) {
352+ ( typeof actual === 'object' && actual !== null ||
353+ typeof actual === 'function') ) {
355354 base = kReadableOperator.notStrictEqualObject;
356355 }
357356
358357 // Only remove lines in case it makes sense to collapse those.
359358 // 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 ) {
363362 res.pop();
364363 }
365364 }
366365
367366 // Only print a single input.
368367 if (res.length === 1) {
369- super(`${base} ${res[0]}`);
368+ super(`${base}${res[0].length > 5 ? '\n\n' : ' '} ${res[0]}`);
370369 } else {
371370 super(`${base}\n\n${res.join('\n')}\n`);
372371 }
373372 } else {
374373 let res = inspectValue(actual);
375- let other = '' ;
374+ let other = inspectValue(expected) ;
376375 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}`;
379379 if (res.length > 1024) {
380380 res = `${res.slice(0, 1021)}...`;
381381 }
382+ super(res);
382383 } else {
383- other = `${inspectValue(expected)}`;
384384 if (res.length > 512) {
385385 res = `${res.slice(0, 509)}...`;
386386 }
387387 if (other.length > 512) {
388388 other = `${other.slice(0, 509)}...`;
389389 }
390390 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`;
392393 } 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+ }
394401 }
402+ super(`${res}${other}`);
395403 }
396- super(`${res}${other}`);
397404 }
398405 }
399406
0 commit comments