fix(expect): highlight diff in toHaveText (#8262)
This commit is contained in:
parent
659b378184
commit
de4464cb9a
|
|
@ -21,12 +21,11 @@ import {
|
||||||
|
|
||||||
import {
|
import {
|
||||||
EXPECTED_COLOR,
|
EXPECTED_COLOR,
|
||||||
getLabelPrinter,
|
|
||||||
matcherErrorMessage,
|
matcherErrorMessage,
|
||||||
matcherHint, MatcherHintOptions,
|
matcherHint, MatcherHintOptions,
|
||||||
printExpected,
|
printExpected,
|
||||||
printReceived,
|
|
||||||
printWithType,
|
printWithType,
|
||||||
|
printDiffOrStringify,
|
||||||
} from 'jest-matcher-utils';
|
} from 'jest-matcher-utils';
|
||||||
import { currentTestInfo } from '../globals';
|
import { currentTestInfo } from '../globals';
|
||||||
import type { Expect } from '../types';
|
import type { Expect } from '../types';
|
||||||
|
|
@ -107,14 +106,17 @@ export async function toMatchText(
|
||||||
const labelExpected = `Expected ${typeof expected === 'string' ? stringSubstring : 'pattern'
|
const labelExpected = `Expected ${typeof expected === 'string' ? stringSubstring : 'pattern'
|
||||||
}`;
|
}`;
|
||||||
const labelReceived = 'Received string';
|
const labelReceived = 'Received string';
|
||||||
const printLabel = getLabelPrinter(labelExpected, labelReceived);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
matcherHint(matcherName, undefined, undefined, matcherOptions) +
|
matcherHint(matcherName, undefined, undefined, matcherOptions) +
|
||||||
'\n\n' +
|
'\n\n' +
|
||||||
`${printLabel(labelExpected)}${printExpected(expected)}\n` +
|
printDiffOrStringify(
|
||||||
`${printLabel(labelReceived)}${printReceived(received)}`
|
expected,
|
||||||
);
|
received,
|
||||||
|
labelExpected,
|
||||||
|
labelReceived,
|
||||||
|
this.expand !== false,
|
||||||
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
return { message, pass };
|
return { message, pass };
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue