File tree Expand file tree Collapse file tree
packages/jest-matchers/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -232,27 +232,13 @@ Received:
232232exports[`.toBe() fails for: [] and [] 1`] = `
233233"<dim>expect(<red>received</><dim>).toBe(<green>expected</><dim>)
234234
235- Expected value to be (using ===):
236- <green>[]</>
237- Received:
238- <red>[]</>
239-
240- Difference:
241-
242- <dim>Compared values have no visual difference."
235+ Looks like you wanted to test for object/array equity with strict \`toBe\` matcher. You probably need to use \`toEqual\` instead."
243236`;
244237
245238exports[`.toBe() fails for: {"a": 1} and {"a": 1} 1`] = `
246239"<dim>expect(<red>received</><dim>).toBe(<green>expected</><dim>)
247240
248- Expected value to be (using ===):
249- <green>{\\"a\\": 1}</>
250- Received:
251- <red>{\\"a\\": 1}</>
252-
253- Difference:
254-
255- <dim>Compared values have no visual difference."
241+ Looks like you wanted to test for object/array equity with strict \`toBe\` matcher. You probably need to use \`toEqual\` instead."
256242`;
257243
258244exports[`.toBe() fails for: {"a": 1} and {"a": 5} 1`] = `
@@ -277,14 +263,7 @@ Difference:
277263exports[`.toBe() fails for: {} and {} 1`] = `
278264"<dim>expect(<red>received</><dim>).toBe(<green>expected</><dim>)
279265
280- Expected value to be (using ===):
281- <green>{}</>
282- Received:
283- <red>{}</>
284-
285- Difference:
286-
287- <dim>Compared values have no visual difference."
266+ Looks like you wanted to test for object/array equity with strict \`toBe\` matcher. You probably need to use \`toEqual\` instead."
288267`;
289268
290269exports[`.toBe() fails for: 1 and 2 1`] = `
Original file line number Diff line number Diff line change @@ -67,6 +67,18 @@ const matchers: MatchersObject = {
6767 `Received:\n` +
6868 ` ${ printReceived ( received ) } `
6969 : ( ) => {
70+ if (
71+ getType ( received ) === getType ( expected ) &&
72+ ( getType ( received ) === 'object' || getType ( expected ) === 'array' ) &&
73+ equals ( received , expected , [ iterableEquality ] )
74+ ) {
75+ return (
76+ matcherHint ( '.toBe' ) +
77+ '\n\n' +
78+ 'Looks like you wanted to test for object/array equity with strict `toBe` matcher. You probably need to use `toEqual` instead.'
79+ ) ;
80+ }
81+
7082 const diffString = diff ( expected , received , {
7183 expand : this . expand ,
7284 } ) ;
You can’t perform that action at this time.
0 commit comments