Skip to content
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
Call chalk.inverse for trailing spaces in jest-matcher-utils
  • Loading branch information
pedrottimark committed Oct 1, 2017
commit 8852ce51d5dad3ae4abd4bc2673f9e4af111474f
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