Repository: jquery/jquery
File: test/runner/reporter.js (JavaScript)

Code before:
				} else if (
					typeof error.expected === "number" &&
					typeof error.actual === "number"
				) {

					// Diff numbers directly
					const value = error.actual - error.expected;
					if ( value > 0 ) {
						diff = [ { added: true, value: `+${ value }` } ];
					} else {
						diff = [ { removed: true, value: `${ value }` } ];
					}
				} else if (
					typeof error.expected === "string" &&
					typeof error.actual === "string"
				) {

					// Diff the characters of strings
					diff = Diff.diffChars( error.expected, error.actual );
				} else if ( error.expected != null && error.actual != null ) {

					// Diff everything else as words
					diff = Diff.diffWords(
						quoteWrap( error.expected ),
						quoteWrap( error.actual )
					);
				}

				if ( diff ) {
					message += "\n";
					message += diff
						.map( ( part ) => {
							if ( part.added ) {
								return chalk.green( part.value );
							}
							if ( part.removed ) {
								return chalk.red( part.value );
							}
							return chalk.gray( part.value );
						} )
						.join( "" );
				}
			}
		}
	}

	console.log( `\n\n${ message }` );

	// Only return failed messages
	if ( test.status === "failed" ) {
		return message;

Review comment (bug):
I think the necessary insight here is that we want to diff type-mismatched values _after serialization_, which `quoteWrap` a) fails to convey, and b) currently does so inconsistently (e.g., it escapes `"` in strings by `\`-prefixing, but does not similarly escape `\`).
```suggestion
					// Diff everything else as words (post-serialization)
					diff = Diff.diffWords(
						serializeForDiff( error.expected ),
						serializeForDiff( error.actual )
					);
```
with
```js
function serializeForDiff( value ) {
	// Use naive serialization for everything except types with confusable values
	if ( typeof value === "string" ) {
		return JSON.stringify(value);
	} else if ( typeof value === "bigint" ) {
		return `${ value }n`;
	} else if ( typeof value === "symbol" ) {
		const ctor = Symbol.keyFor(value) !== undefined ? "Symbol.for" : "Symbol";
		return `${ctor}(${JSON.stringify(value.description)})`;
	}
	return `${ value }`;
}
```

Code after:

					// Diff objects
					diff = Diff.diffJson( error.expected, error.actual );
				} else if (
					typeof error.expected === "number" &&
					typeof error.actual === "number"
				) {

					// Diff numbers directly
					const value = error.actual - error.expected;
					if ( value > 0 ) {
						diff = [ { added: true, value: `+${ value }` } ];
					} else {
						diff = [ { removed: true, value: `${ value }` } ];
					}
				} else if (
					typeof error.expected === "string" &&
					typeof error.actual === "string"
				) {

					// Diff the characters of strings
					diff = Diff.diffChars( error.expected, error.actual );
				} else {

					// Diff everything else as words
					diff = Diff.diffWords(
						serializeForDiff( error.expected ),
						serializeForDiff( error.actual )
					);
				}

				if ( diff ) {
					message += "\n";
					message += diff
						.map( ( part ) => {
							if ( part.added ) {
								return chalk.green( part.value );
							}
							if ( part.removed ) {
								return chalk.red( part.value );
							}
							return chalk.gray( part.value );
						} )
						.join( "" );
				}
			}
		}
	}

	console.log( `\n\n${ message }` );