Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call chalk.inverse for trailing spaces in jest-matcher-utils #4578

Merged
merged 1 commit into from
Oct 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@ Received:
<red>\\"abc\\"</>"
`;

exports[`.toBe() fails for: "with
trailing space" and "without trailing space" 1`] = `
"<dim>expect(</><red>received</><dim>).toBe(</><green>expected</><dim>)</>

Expected value to be (using ===):
<green>\\"without trailing space\\"</>
Received:
<red>\\"with<inverse> </></>
<red>trailing space\\"</>"
`;

exports[`.toBe() fails for: [] and [] 1`] = `
"<dim>expect(</><red>received</><dim>).toBe(</><green>expected</><dim>)</>

Expand Down
1 change: 1 addition & 0 deletions packages/expect/src/__tests__/matchers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ describe('.toBe()', () => {
[{a: 1}, {a: 1}],
[{a: 1}, {a: 5}],
['abc', 'cde'],
['with \ntrailing space', 'without trailing space'],
[[], []],
[null, undefined],
].forEach(([a, b]) => {
Expand Down
3 changes: 1 addition & 2 deletions packages/expect/src/to_throw_matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import getType from 'jest-get-type';
import {escapeStrForRegex} from 'jest-regex-util';
import {formatStackTrace, separateMessageFromStack} from 'jest-message-util';
import {
RECEIVED_BG,
RECEIVED_COLOR,
highlightTrailingWhitespace,
matcherHint,
Expand Down Expand Up @@ -173,7 +172,7 @@ const printActualErrorMessage = error => {
`Instead, it threw:\n` +
RECEIVED_COLOR(
' ' +
highlightTrailingWhitespace(message, RECEIVED_BG) +
highlightTrailingWhitespace(message) +
formatStackTrace(
stack,
{
Expand Down
12 changes: 4 additions & 8 deletions packages/jest-matcher-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ const PLUGINS = [
];

export const EXPECTED_COLOR = chalk.green;
export const EXPECTED_BG = chalk.bgGreen;
export const RECEIVED_COLOR = chalk.red;
export const RECEIVED_BG = chalk.bgRed;

const NUMBERS = [
'zero',
Expand Down Expand Up @@ -76,15 +74,13 @@ export const stringify = (object: any, maxDepth?: number = 10): string => {
: result;
};

export const highlightTrailingWhitespace = (
text: string,
bgColor: Function,
): string => text.replace(/\s+$/gm, bgColor('$&'));
export const highlightTrailingWhitespace = (text: string): string =>
text.replace(/\s+$/gm, chalk.inverse('$&'));

export const printReceived = (object: any) =>
highlightTrailingWhitespace(RECEIVED_COLOR(stringify(object)), RECEIVED_BG);
RECEIVED_COLOR(highlightTrailingWhitespace(stringify(object)));
export const printExpected = (value: any) =>
highlightTrailingWhitespace(EXPECTED_COLOR(stringify(value)), EXPECTED_BG);
EXPECTED_COLOR(highlightTrailingWhitespace(stringify(value)));

export const printWithType = (
name: string,
Expand Down