Skip to content

Commit

Permalink
Revert "Just add a message at the bottom instead of replacing it"
Browse files Browse the repository at this point in the history
This reverts commit 3d726d5.
  • Loading branch information
rogeliog committed Aug 17, 2017
1 parent 3d726d5 commit b0fe627
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,27 +232,13 @@ Received:
exports[`.toBe() fails for: [] and [] 1`] = `
"<dim>expect(<red>received</><dim>).toBe(<green>expected</><dim>)

Expected value to be (using ===):
<green>[]</>
Received:
<red>[]</>

Difference:

<dim>Compared values have no visual difference. <dim>Looks like you wanted to test for object/array equality with strict \`toBe\` matcher. You probably need to use \`toEqual\` instead."
Looks like you wanted to test for object/array equity with strict \`toBe\` matcher. You probably need to use \`toEqual\` instead."
`;

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

Expected value to be (using ===):
<green>{\\"a\\": 1}</>
Received:
<red>{\\"a\\": 1}</>

Difference:

<dim>Compared values have no visual difference. <dim>Looks like you wanted to test for object/array equality with strict \`toBe\` matcher. You probably need to use \`toEqual\` instead."
Looks like you wanted to test for object/array equity with strict \`toBe\` matcher. You probably need to use \`toEqual\` instead."
`;

exports[`.toBe() fails for: {"a": 1} and {"a": 5} 1`] = `
Expand All @@ -277,14 +263,7 @@ Difference:
exports[`.toBe() fails for: {} and {} 1`] = `
"<dim>expect(<red>received</><dim>).toBe(<green>expected</><dim>)

Expected value to be (using ===):
<green>{}</>
Received:
<red>{}</>

Difference:

<dim>Compared values have no visual difference. <dim>Looks like you wanted to test for object/array equality with strict \`toBe\` matcher. You probably need to use \`toEqual\` instead."
Looks like you wanted to test for object/array equity with strict \`toBe\` matcher. You probably need to use \`toEqual\` instead."
`;

exports[`.toBe() fails for: 1 and 2 1`] = `
Expand Down
13 changes: 5 additions & 8 deletions packages/jest-matchers/src/matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import type {MatchersObject} from 'types/Matchers';

import chalk from 'chalk';
import diff from 'jest-diff';
import getType from 'jest-get-type';
import {escapeStrForRegex} from 'jest-regex-util';
Expand Down Expand Up @@ -68,31 +67,29 @@ const matchers: MatchersObject = {
`Received:\n` +
` ${printReceived(received)}`
: () => {
let suggestToEqual;

if (
getType(received) === getType(expected) &&
(getType(received) === 'object' || getType(expected) === 'array') &&
equals(received, expected, [iterableEquality])
) {
suggestToEqual = chalk.dim(
'Looks like you wanted to test for object/array equality with strict `toBe` matcher. You probably need to use `toEqual` instead.',
return (
matcherHint('.toBe') +
'\n\n' +
'Looks like you wanted to test for object/array equity with strict `toBe` matcher. You probably need to use `toEqual` instead.'
);
}

const diffString = diff(expected, received, {
expand: this.expand,
});

return (
matcherHint('.toBe') +
'\n\n' +
`Expected value to be (using ===):\n` +
` ${printExpected(expected)}\n` +
`Received:\n` +
` ${printReceived(received)}` +
(diffString ? `\n\nDifference:\n\n${diffString}` : '') +
(suggestToEqual ? ` ${suggestToEqual}` : '')
(diffString ? `\n\nDifference:\n\n${diffString}` : '')
);
};

Expand Down

0 comments on commit b0fe627

Please sign in to comment.