diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cb720fb984c..9efb72ecf5a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -90,6 +90,7 @@ - `[jest-config]` Use strings instead of `RegExp` instances in normalized configuration ([#7251](https://github.com/facebook/jest/pull/7251)) - `[jest-circus]` Make sure to display real duration even if time is mocked ([#7264](https://github.com/facebook/jest/pull/7264)) - `[expect]` Improves the failing message for `toStrictEqual` matcher. ([#7224](https://github.com/facebook/jest/pull/7224)) +- `[expect]` Improves the failing message for `toEqual` matcher. ([#7325](https://github.com/facebook/jest/pull/7325)) - `[jest-resolve]` Fix not being able to resolve path to mapped file with custom platform ([#7312](https://github.com/facebook/jest/pull/7312)) - `[jest-message-util]` Improve parsing of error messages for unusually formatted stack traces ([#7319](https://github.com/facebook/jest/pull/7319)) - `[jest-runtime]` Ensure error message text is not lost on errors with code frames ([#7319](https://github.com/facebook/jest/pull/7319)) diff --git a/e2e/__tests__/__snapshots__/failures.test.js.snap b/e2e/__tests__/__snapshots__/failures.test.js.snap index 467a8bd7a448..4c00d72b044f 100644 --- a/e2e/__tests__/__snapshots__/failures.test.js.snap +++ b/e2e/__tests__/__snapshots__/failures.test.js.snap @@ -272,10 +272,8 @@ exports[`works with assertions in separate files 1`] = ` expect(received).toEqual(expected) - Expected value to equal: - 2 - Received: - 1 + Expected: 2 + Received: 1 10 | 11 | module.exports = (one: any, two: any) => { @@ -302,11 +300,6 @@ exports[`works with async failures 1`] = ` expect(received).toEqual(expected) - Expected value to equal: - {\\"baz\\": \\"bar\\"} - Received: - {\\"foo\\": \\"bar\\"} - Difference: - Expected @@ -331,11 +324,6 @@ exports[`works with async failures 1`] = ` expect(received).toEqual(expected) - Expected value to equal: - {\\"baz\\": \\"bar\\"} - Received: - {\\"foo\\": \\"bar\\"} - Difference: - Expected diff --git a/packages/expect/src/__tests__/__snapshots__/extend.test.js.snap b/packages/expect/src/__tests__/__snapshots__/extend.test.js.snap index 73440c1c56ea..fa8c8daae7bc 100644 --- a/packages/expect/src/__tests__/__snapshots__/extend.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/extend.test.js.snap @@ -3,11 +3,6 @@ exports[`defines asymmetric unary matchers 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - {\\"value\\": toBeDivisibleBy<2>} -Received: - {\\"value\\": 3} - Difference: - Expected @@ -22,11 +17,6 @@ Difference: exports[`defines asymmetric unary matchers that can be prefixed by not 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - {\\"value\\": not.toBeDivisibleBy<2>} -Received: - {\\"value\\": 2} - Difference: - Expected @@ -41,11 +31,6 @@ Difference: exports[`defines asymmetric variadic matchers 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - {\\"value\\": toBeWithinRange<4, 11>} -Received: - {\\"value\\": 3} - Difference: - Expected @@ -60,11 +45,6 @@ Difference: exports[`defines asymmetric variadic matchers that can be prefixed by not 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - {\\"value\\": not.toBeWithinRange<1, 3>} -Received: - {\\"value\\": 2} - Difference: - Expected diff --git a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap index 19fe16e74e51..4be8e0d6e1ed 100644 --- a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap @@ -1711,103 +1711,83 @@ Received has value: null" `; exports[`.toEqual() {pass: false} expect("Alice").not.toEqual({"asymmetricMatch": [Function asymmetricMatch]}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - {\\"asymmetricMatch\\": [Function asymmetricMatch]} -Received: - \\"Alice\\"" +Expected: {\\"asymmetricMatch\\": [Function asymmetricMatch]} +Received: \\"Alice\\"" `; exports[`.toEqual() {pass: false} expect("Eve").toEqual({"asymmetricMatch": [Function asymmetricMatch]}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - {\\"asymmetricMatch\\": [Function asymmetricMatch]} -Received: - \\"Eve\\"" +Expected: {\\"asymmetricMatch\\": [Function asymmetricMatch]} +Received: \\"Eve\\"" `; exports[`.toEqual() {pass: false} expect("abc").not.toEqual("abc") 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - \\"abc\\" -Received: - \\"abc\\"" +Expected: \\"abc\\" +Received: \\"abc\\"" `; exports[`.toEqual() {pass: false} expect("abcd").not.toEqual(StringContaining "bc") 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - StringContaining \\"bc\\" -Received: - \\"abcd\\"" +Expected: StringContaining \\"bc\\" +Received: \\"abcd\\"" `; exports[`.toEqual() {pass: false} expect("abcd").not.toEqual(StringMatching /bc/) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - StringMatching /bc/ -Received: - \\"abcd\\"" +Expected: StringMatching /bc/ +Received: \\"abcd\\"" `; exports[`.toEqual() {pass: false} expect("abd").toEqual(StringContaining "bc") 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - StringContaining \\"bc\\" -Received: - \\"abd\\"" +Expected: StringContaining \\"bc\\" +Received: \\"abd\\"" `; exports[`.toEqual() {pass: false} expect("abd").toEqual(StringMatching /bc/i) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - StringMatching /bc/i -Received: - \\"abd\\"" +Expected: StringMatching /bc/i +Received: \\"abd\\"" `; exports[`.toEqual() {pass: false} expect("banana").toEqual("apple") 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - \\"apple\\" -Received: - \\"banana\\"" +Difference: + +- Expected ++ Received + +- apple ++ banana" `; exports[`.toEqual() {pass: false} expect([1, 2, 3]).not.toEqual(ArrayContaining [2, 3]) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - ArrayContaining [2, 3] -Received: - [1, 2, 3]" +Expected: ArrayContaining [2, 3] +Received: [1, 2, 3]" `; exports[`.toEqual() {pass: false} expect([1, 2]).not.toEqual([1, 2]) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - [1, 2] -Received: - [1, 2]" +Expected: [1, 2] +Received: [1, 2]" `; exports[`.toEqual() {pass: false} expect([1, 2]).toEqual([2, 1]) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - [2, 1] -Received: - [1, 2] - Difference: - Expected @@ -1823,11 +1803,6 @@ Difference: exports[`.toEqual() {pass: false} expect([1, 3]).toEqual(ArrayContaining [1, 2]) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - ArrayContaining [1, 2] -Received: - [1, 3] - Difference: - Expected @@ -1842,22 +1817,15 @@ Difference: `; exports[`.toEqual() {pass: false} expect([1]).not.toEqual([1]) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - [1] -Received: - [1]" +Expected: [1] +Received: [1]" `; exports[`.toEqual() {pass: false} expect([1]).toEqual([2]) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - [2] -Received: - [1] - Difference: - Expected @@ -1870,40 +1838,29 @@ Difference: `; exports[`.toEqual() {pass: false} expect([Function anonymous]).not.toEqual(Any) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Any -Received: - [Function anonymous]" +Expected: Any +Received: [Function anonymous]" `; exports[`.toEqual() {pass: false} expect({"a": 1, "b": [Function b], "c": true}).not.toEqual({"a": 1, "b": Any, "c": Anything}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - {\\"a\\": 1, \\"b\\": Any, \\"c\\": Anything} -Received: - {\\"a\\": 1, \\"b\\": [Function b], \\"c\\": true}" +Expected: {\\"a\\": 1, \\"b\\": Any, \\"c\\": Anything} +Received: {\\"a\\": 1, \\"b\\": [Function b], \\"c\\": true}" `; exports[`.toEqual() {pass: false} expect({"a": 1, "b": 2}).not.toEqual(ObjectContaining {"a": 1}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - ObjectContaining {\\"a\\": 1} -Received: - {\\"a\\": 1, \\"b\\": 2}" +Expected: ObjectContaining {\\"a\\": 1} +Received: {\\"a\\": 1, \\"b\\": 2}" `; exports[`.toEqual() {pass: false} expect({"a": 1, "b": 2}).toEqual(ObjectContaining {"a": 2}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - ObjectContaining {\\"a\\": 2} -Received: - {\\"a\\": 1, \\"b\\": 2} - Difference: - Expected @@ -1920,11 +1877,6 @@ Difference: exports[`.toEqual() {pass: false} expect({"a": 5}).toEqual({"b": 6}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - {\\"b\\": 6} -Received: - {\\"a\\": 5} - Difference: - Expected @@ -1937,22 +1889,15 @@ Difference: `; exports[`.toEqual() {pass: false} expect({"a": 99}).not.toEqual({"a": 99}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - {\\"a\\": 99} -Received: - {\\"a\\": 99}" +Expected: {\\"a\\": 99} +Received: {\\"a\\": 99}" `; exports[`.toEqual() {pass: false} expect({"target": {"nodeType": 1, "value": "a"}}).toEqual({"target": {"nodeType": 1, "value": "b"}}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - {\\"target\\": {\\"nodeType\\": 1, \\"value\\": \\"b\\"}} -Received: - {\\"target\\": {\\"nodeType\\": 1, \\"value\\": \\"a\\"}} - Difference: - Expected @@ -1968,75 +1913,50 @@ Difference: `; exports[`.toEqual() {pass: false} expect({}).not.toEqual({}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - {} -Received: - {}" +Expected: {} +Received: {}" `; exports[`.toEqual() {pass: false} expect(0).toEqual(-0) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - -0 -Received: - 0 - -Difference: - -Compared values have no visual difference." +Expected: -0 +Received: 0" `; exports[`.toEqual() {pass: false} expect(1).not.toEqual(1) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - 1 -Received: - 1" +Expected: 1 +Received: 1" `; exports[`.toEqual() {pass: false} expect(1).toEqual(2) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - 2 -Received: - 1" +Expected: 2 +Received: 1" `; exports[`.toEqual() {pass: false} expect(1).toEqual(ArrayContaining [1, 2]) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - ArrayContaining [1, 2] -Received: - 1 - -Difference: - - Comparing two different types of values. Expected array but received number." +Expected: ArrayContaining [1, 2] +Received: 1" `; exports[`.toEqual() {pass: false} expect(Immutable.List [1, 2]).not.toEqual(Immutable.List [1, 2]) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Immutable.List [1, 2] -Received: - Immutable.List [1, 2]" +Expected: Immutable.List [1, 2] +Received: Immutable.List [1, 2]" `; exports[`.toEqual() {pass: false} expect(Immutable.List [1, 2]).toEqual(Immutable.List [2, 1]) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Immutable.List [2, 1] -Received: - Immutable.List [1, 2] - Difference: - Expected @@ -2050,22 +1970,15 @@ Difference: `; exports[`.toEqual() {pass: false} expect(Immutable.List [1]).not.toEqual(Immutable.List [1]) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Immutable.List [1] -Received: - Immutable.List [1]" +Expected: Immutable.List [1] +Received: Immutable.List [1]" `; exports[`.toEqual() {pass: false} expect(Immutable.List [1]).toEqual(Immutable.List [2]) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Immutable.List [2] -Received: - Immutable.List [1] - Difference: - Expected @@ -2078,22 +1991,15 @@ Difference: `; exports[`.toEqual() {pass: false} expect(Immutable.Map {"1": Immutable.Map {"2": {"a": 99}}}).not.toEqual(Immutable.Map {"1": Immutable.Map {"2": {"a": 99}}}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Immutable.Map {\\"1\\": Immutable.Map {\\"2\\": {\\"a\\": 99}}} -Received: - Immutable.Map {\\"1\\": Immutable.Map {\\"2\\": {\\"a\\": 99}}}" +Expected: Immutable.Map {\\"1\\": Immutable.Map {\\"2\\": {\\"a\\": 99}}} +Received: Immutable.Map {\\"1\\": Immutable.Map {\\"2\\": {\\"a\\": 99}}}" `; exports[`.toEqual() {pass: false} expect(Immutable.Map {"1": Immutable.Map {"2": {"a": 99}}}).toEqual(Immutable.Map {"1": Immutable.Map {"2": {"a": 11}}}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Immutable.Map {\\"1\\": Immutable.Map {\\"2\\": {\\"a\\": 11}}} -Received: - Immutable.Map {\\"1\\": Immutable.Map {\\"2\\": {\\"a\\": 99}}} - Difference: - Expected @@ -2112,11 +2018,6 @@ Difference: exports[`.toEqual() {pass: false} expect(Immutable.Map {"a": 0}).toEqual(Immutable.Map {"b": 0}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Immutable.Map {\\"b\\": 0} -Received: - Immutable.Map {\\"a\\": 0} - Difference: - Expected @@ -2131,11 +2032,6 @@ Difference: exports[`.toEqual() {pass: false} expect(Immutable.Map {"v": 1}).toEqual(Immutable.Map {"v": 2}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Immutable.Map {\\"v\\": 2} -Received: - Immutable.Map {\\"v\\": 1} - Difference: - Expected @@ -2148,49 +2044,36 @@ Difference: `; exports[`.toEqual() {pass: false} expect(Immutable.Map {}).not.toEqual(Immutable.Map {}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Immutable.Map {} -Received: - Immutable.Map {}" +Expected: Immutable.Map {} +Received: Immutable.Map {}" `; exports[`.toEqual() {pass: false} expect(Immutable.Map {1: "one", 2: "two"}).not.toEqual(Immutable.Map {1: "one", 2: "two"}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Immutable.Map {1: \\"one\\", 2: \\"two\\"} -Received: - Immutable.Map {1: \\"one\\", 2: \\"two\\"}" +Expected: Immutable.Map {1: \\"one\\", 2: \\"two\\"} +Received: Immutable.Map {1: \\"one\\", 2: \\"two\\"}" `; exports[`.toEqual() {pass: false} expect(Immutable.Map {1: "one", 2: "two"}).not.toEqual(Immutable.Map {2: "two", 1: "one"}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Immutable.Map {2: \\"two\\", 1: \\"one\\"} -Received: - Immutable.Map {1: \\"one\\", 2: \\"two\\"}" +Expected: Immutable.Map {2: \\"two\\", 1: \\"one\\"} +Received: Immutable.Map {1: \\"one\\", 2: \\"two\\"}" `; exports[`.toEqual() {pass: false} expect(Immutable.OrderedMap {1: "one", 2: "two"}).not.toEqual(Immutable.OrderedMap {1: "one", 2: "two"}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Immutable.OrderedMap {1: \\"one\\", 2: \\"two\\"} -Received: - Immutable.OrderedMap {1: \\"one\\", 2: \\"two\\"}" +Expected: Immutable.OrderedMap {1: \\"one\\", 2: \\"two\\"} +Received: Immutable.OrderedMap {1: \\"one\\", 2: \\"two\\"}" `; exports[`.toEqual() {pass: false} expect(Immutable.OrderedMap {1: "one", 2: "two"}).toEqual(Immutable.OrderedMap {2: "two", 1: "one"}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Immutable.OrderedMap {2: \\"two\\", 1: \\"one\\"} -Received: - Immutable.OrderedMap {1: \\"one\\", 2: \\"two\\"} - Difference: - Expected @@ -2204,31 +2087,22 @@ Difference: `; exports[`.toEqual() {pass: false} expect(Immutable.OrderedSet []).not.toEqual(Immutable.OrderedSet []) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Immutable.OrderedSet [] -Received: - Immutable.OrderedSet []" +Expected: Immutable.OrderedSet [] +Received: Immutable.OrderedSet []" `; exports[`.toEqual() {pass: false} expect(Immutable.OrderedSet [1, 2]).not.toEqual(Immutable.OrderedSet [1, 2]) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Immutable.OrderedSet [1, 2] -Received: - Immutable.OrderedSet [1, 2]" +Expected: Immutable.OrderedSet [1, 2] +Received: Immutable.OrderedSet [1, 2]" `; exports[`.toEqual() {pass: false} expect(Immutable.OrderedSet [1, 2]).toEqual(Immutable.OrderedSet [2, 1]) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Immutable.OrderedSet [2, 1] -Received: - Immutable.OrderedSet [1, 2] - Difference: - Expected @@ -2242,40 +2116,29 @@ Difference: `; exports[`.toEqual() {pass: false} expect(Immutable.Set []).not.toEqual(Immutable.Set []) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Immutable.Set [] -Received: - Immutable.Set []" +Expected: Immutable.Set [] +Received: Immutable.Set []" `; exports[`.toEqual() {pass: false} expect(Immutable.Set [1, 2]).not.toEqual(Immutable.Set [1, 2]) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Immutable.Set [1, 2] -Received: - Immutable.Set [1, 2]" +Expected: Immutable.Set [1, 2] +Received: Immutable.Set [1, 2]" `; exports[`.toEqual() {pass: false} expect(Immutable.Set [1, 2]).not.toEqual(Immutable.Set [2, 1]) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Immutable.Set [2, 1] -Received: - Immutable.Set [1, 2]" +Expected: Immutable.Set [2, 1] +Received: Immutable.Set [1, 2]" `; exports[`.toEqual() {pass: false} expect(Immutable.Set [1, 2]).toEqual(Immutable.Set []) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Immutable.Set [] -Received: - Immutable.Set [1, 2] - Difference: - Expected @@ -2291,11 +2154,6 @@ Difference: exports[`.toEqual() {pass: false} expect(Immutable.Set [1, 2]).toEqual(Immutable.Set [1, 2, 3]) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Immutable.Set [1, 2, 3] -Received: - Immutable.Set [1, 2] - Difference: - Expected @@ -2311,11 +2169,6 @@ Difference: exports[`.toEqual() {pass: false} expect(Map {"a" => 0}).toEqual(Map {"b" => 0}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Map {\\"b\\" => 0} -Received: - Map {\\"a\\" => 0} - Difference: - Expected @@ -2330,11 +2183,6 @@ Difference: exports[`.toEqual() {pass: false} expect(Map {"v" => 1}).toEqual(Map {"v" => 2}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Map {\\"v\\" => 2} -Received: - Map {\\"v\\" => 1} - Difference: - Expected @@ -2349,11 +2197,6 @@ Difference: exports[`.toEqual() {pass: false} expect(Map {["v"] => 1}).toEqual(Map {["v"] => 2}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Map {[\\"v\\"] => 2} -Received: - Map {[\\"v\\"] => 1} - Difference: - Expected @@ -2368,40 +2211,29 @@ Difference: `; exports[`.toEqual() {pass: false} expect(Map {[1] => "one", [2] => "two", [3] => "three", [3] => "four"}).not.toEqual(Map {[3] => "three", [3] => "four", [2] => "two", [1] => "one"}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Map {[3] => \\"three\\", [3] => \\"four\\", [2] => \\"two\\", [1] => \\"one\\"} -Received: - Map {[1] => \\"one\\", [2] => \\"two\\", [3] => \\"three\\", [3] => \\"four\\"}" +Expected: Map {[3] => \\"three\\", [3] => \\"four\\", [2] => \\"two\\", [1] => \\"one\\"} +Received: Map {[1] => \\"one\\", [2] => \\"two\\", [3] => \\"three\\", [3] => \\"four\\"}" `; exports[`.toEqual() {pass: false} expect(Map {[1] => "one", [2] => "two"}).not.toEqual(Map {[2] => "two", [1] => "one"}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Map {[2] => \\"two\\", [1] => \\"one\\"} -Received: - Map {[1] => \\"one\\", [2] => \\"two\\"}" +Expected: Map {[2] => \\"two\\", [1] => \\"one\\"} +Received: Map {[1] => \\"one\\", [2] => \\"two\\"}" `; exports[`.toEqual() {pass: false} expect(Map {[1] => Map {[1] => "one"}, [2] => Map {[2] => "two"}}).not.toEqual(Map {[2] => Map {[2] => "two"}, [1] => Map {[1] => "one"}}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Map {[2] => Map {[2] => \\"two\\"}, [1] => Map {[1] => \\"one\\"}} -Received: - Map {[1] => Map {[1] => \\"one\\"}, [2] => Map {[2] => \\"two\\"}}" +Expected: Map {[2] => Map {[2] => \\"two\\"}, [1] => Map {[1] => \\"one\\"}} +Received: Map {[1] => Map {[1] => \\"one\\"}, [2] => Map {[2] => \\"two\\"}}" `; exports[`.toEqual() {pass: false} expect(Map {[1] => Map {[1] => "one"}}).toEqual(Map {[1] => Map {[1] => "two"}}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Map {[1] => Map {[1] => \\"two\\"}} -Received: - Map {[1] => Map {[1] => \\"one\\"}} - Difference: - Expected @@ -2420,62 +2252,43 @@ Difference: `; exports[`.toEqual() {pass: false} expect(Map {{"a": 1} => "one", {"b": 2} => "two"}).not.toEqual(Map {{"b": 2} => "two", {"a": 1} => "one"}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Map {{\\"b\\": 2} => \\"two\\", {\\"a\\": 1} => \\"one\\"} -Received: - Map {{\\"a\\": 1} => \\"one\\", {\\"b\\": 2} => \\"two\\"}" +Expected: Map {{\\"b\\": 2} => \\"two\\", {\\"a\\": 1} => \\"one\\"} +Received: Map {{\\"a\\": 1} => \\"one\\", {\\"b\\": 2} => \\"two\\"}" `; exports[`.toEqual() {pass: false} expect(Map {}).not.toEqual(Map {}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Map {} -Received: - Map {}" +Expected: Map {} +Received: Map {}" `; exports[`.toEqual() {pass: false} expect(Map {}).toEqual(Set {}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Set {} -Received: - Map {} - -Difference: - - Comparing two different types of values. Expected set but received map." +Expected: Set {} +Received: Map {}" `; exports[`.toEqual() {pass: false} expect(Map {1 => "one", 2 => "two"}).not.toEqual(Map {1 => "one", 2 => "two"}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Map {1 => \\"one\\", 2 => \\"two\\"} -Received: - Map {1 => \\"one\\", 2 => \\"two\\"}" +Expected: Map {1 => \\"one\\", 2 => \\"two\\"} +Received: Map {1 => \\"one\\", 2 => \\"two\\"}" `; exports[`.toEqual() {pass: false} expect(Map {1 => "one", 2 => "two"}).not.toEqual(Map {2 => "two", 1 => "one"}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Map {2 => \\"two\\", 1 => \\"one\\"} -Received: - Map {1 => \\"one\\", 2 => \\"two\\"}" +Expected: Map {2 => \\"two\\", 1 => \\"one\\"} +Received: Map {1 => \\"one\\", 2 => \\"two\\"}" `; exports[`.toEqual() {pass: false} expect(Map {1 => "one", 2 => "two"}).toEqual(Map {1 => "one"}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Map {1 => \\"one\\"} -Received: - Map {1 => \\"one\\", 2 => \\"two\\"} - Difference: - Expected @@ -2488,40 +2301,29 @@ Difference: `; exports[`.toEqual() {pass: false} expect(Map {1 => ["one"], 2 => ["two"]}).not.toEqual(Map {2 => ["two"], 1 => ["one"]}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Map {2 => [\\"two\\"], 1 => [\\"one\\"]} -Received: - Map {1 => [\\"one\\"], 2 => [\\"two\\"]}" +Expected: Map {2 => [\\"two\\"], 1 => [\\"one\\"]} +Received: Map {1 => [\\"one\\"], 2 => [\\"two\\"]}" `; exports[`.toEqual() {pass: false} expect(Set {[1], [2], [3], [3]}).not.toEqual(Set {[3], [3], [2], [1]}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Set {[3], [3], [2], [1]} -Received: - Set {[1], [2], [3], [3]}" +Expected: Set {[3], [3], [2], [1]} +Received: Set {[1], [2], [3], [3]}" `; exports[`.toEqual() {pass: false} expect(Set {[1], [2]}).not.toEqual(Set {[2], [1]}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Set {[2], [1]} -Received: - Set {[1], [2]}" +Expected: Set {[2], [1]} +Received: Set {[1], [2]}" `; exports[`.toEqual() {pass: false} expect(Set {[1], [2]}).toEqual(Set {[1], [2], [2]}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Set {[1], [2], [2]} -Received: - Set {[1], [2]} - Difference: - Expected @@ -2542,11 +2344,6 @@ Difference: exports[`.toEqual() {pass: false} expect(Set {[1], [2]}).toEqual(Set {[1], [2], [3]}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Set {[1], [2], [3]} -Received: - Set {[1], [2]} - Difference: - Expected @@ -2565,49 +2362,36 @@ Difference: `; exports[`.toEqual() {pass: false} expect(Set {{"a": 1}, {"b": 2}}).not.toEqual(Set {{"b": 2}, {"a": 1}}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Set {{\\"b\\": 2}, {\\"a\\": 1}} -Received: - Set {{\\"a\\": 1}, {\\"b\\": 2}}" +Expected: Set {{\\"b\\": 2}, {\\"a\\": 1}} +Received: Set {{\\"a\\": 1}, {\\"b\\": 2}}" `; exports[`.toEqual() {pass: false} expect(Set {}).not.toEqual(Set {}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Set {} -Received: - Set {}" +Expected: Set {} +Received: Set {}" `; exports[`.toEqual() {pass: false} expect(Set {1, 2}).not.toEqual(Set {1, 2}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Set {1, 2} -Received: - Set {1, 2}" +Expected: Set {1, 2} +Received: Set {1, 2}" `; exports[`.toEqual() {pass: false} expect(Set {1, 2}).not.toEqual(Set {2, 1}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Set {2, 1} -Received: - Set {1, 2}" +Expected: Set {2, 1} +Received: Set {1, 2}" `; exports[`.toEqual() {pass: false} expect(Set {1, 2}).toEqual(Set {}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Set {} -Received: - Set {1, 2} - Difference: - Expected @@ -2623,11 +2407,6 @@ Difference: exports[`.toEqual() {pass: false} expect(Set {1, 2}).toEqual(Set {1, 2, 3}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Set {1, 2, 3} -Received: - Set {1, 2} - Difference: - Expected @@ -2641,22 +2420,15 @@ Difference: `; exports[`.toEqual() {pass: false} expect(Set {Set {[1]}, Set {[2]}}).not.toEqual(Set {Set {[2]}, Set {[1]}}) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Set {Set {[2]}, Set {[1]}} -Received: - Set {Set {[1]}, Set {[2]}}" +Expected: Set {Set {[2]}, Set {[1]}} +Received: Set {Set {[1]}, Set {[2]}}" `; exports[`.toEqual() {pass: false} expect(Set {Set {1}, Set {2}}).toEqual(Set {Set {1}, Set {3}}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Set {Set {1}, Set {3}} -Received: - Set {Set {1}, Set {2}} - Difference: - Expected @@ -2676,76 +2448,71 @@ Difference: exports[`.toEqual() {pass: false} expect(false).toEqual(ObjectContaining {"a": 2}) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - ObjectContaining {\\"a\\": 2} -Received: - false - -Difference: - - Comparing two different types of values. Expected object but received boolean." +Expected: ObjectContaining {\\"a\\": 2} +Received: false" `; exports[`.toEqual() {pass: false} expect(null).toEqual(undefined) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - undefined -Received: - null - -Difference: - - Comparing two different types of values. Expected undefined but received null." +Expected: undefined +Received: null" `; exports[`.toEqual() {pass: false} expect(true).not.toEqual(Anything) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - Anything -Received: - true" +Expected: Anything +Received: true" `; exports[`.toEqual() {pass: false} expect(true).not.toEqual(true) 1`] = ` -"expect(received).not.toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to not equal: - true -Received: - true" +Expected: true +Received: true" `; exports[`.toEqual() {pass: false} expect(true).toEqual(false) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - false -Received: - true" +Expected: false +Received: true" `; exports[`.toEqual() {pass: false} expect(undefined).toEqual(Any) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Any -Received: - undefined +Expected: Any +Received: undefined" +`; -Difference: +exports[`.toEqual() {pass: false} expect(undefined).toEqual(Anything) 1`] = ` +"expect(received).toEqual(expected) - Comparing two different types of values. Expected function but received undefined." +Expected: Anything +Received: undefined" `; -exports[`.toEqual() {pass: false} expect(undefined).toEqual(Anything) 1`] = ` +exports[`.toEqual() failure message matches the expected snapshot 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Anything -Received: - undefined" +Difference: + +- Expected ++ Received + + Object { +- \\"a\\": 2, ++ \\"a\\": 1, + }" +`; + +exports[`.toEqual() failure message matches the expected snapshot 2`] = ` +"expect(received).not.toEqual(expected) + +Expected: {\\"a\\": 1} +Received: {\\"a\\": 1}" `; exports[`.toHaveLength {pass: false} expect("").toHaveLength(1) 1`] = ` diff --git a/packages/expect/src/__tests__/matchers.test.js b/packages/expect/src/__tests__/matchers.test.js index 15c1f9c62c56..321220daa061 100644 --- a/packages/expect/src/__tests__/matchers.test.js +++ b/packages/expect/src/__tests__/matchers.test.js @@ -500,6 +500,16 @@ describe('.toEqual()', () => { } }); + test('failure message matches the expected snapshot', () => { + expect(() => + jestExpect({a: 1}).toEqual({a: 2}), + ).toThrowErrorMatchingSnapshot(); + + expect(() => + jestExpect({a: 1}).not.toEqual({a: 1}), + ).toThrowErrorMatchingSnapshot(); + }); + test('symbol based keys in arrays are processed correctly', () => { const mySymbol = Symbol('test'); const actual1 = []; diff --git a/packages/expect/src/matchers.js b/packages/expect/src/matchers.js index eb2609442f43..4e68a4ee2849 100644 --- a/packages/expect/src/matchers.js +++ b/packages/expect/src/matchers.js @@ -384,24 +384,24 @@ const matchers: MatchersObject = { const message = pass ? () => - matcherHint('.not.toEqual') + + matcherHint('.toEqual', undefined, undefined, { + isNot: this.isNot, + }) + '\n\n' + - `Expected value to not equal:\n` + - ` ${printExpected(expected)}\n` + - `Received:\n` + - ` ${printReceived(received)}` + `Expected: ${printExpected(expected)}\n` + + `Received: ${printReceived(received)}` : () => { - const oneline = isOneline(expected, received); const diffString = diff(expected, received, {expand: this.expand}); return ( - matcherHint('.toEqual') + + matcherHint('.toEqual', undefined, undefined, { + isNot: this.isNot, + }) + '\n\n' + - `Expected value to equal:\n` + - ` ${printExpected(expected)}\n` + - `Received:\n` + - ` ${printReceived(received)}` + - (diffString && !oneline ? `\n\nDifference:\n\n${diffString}` : '') + (diffString && diffString.includes('- Expect') + ? `Difference:\n\n${diffString}` + : `Expected: ${printExpected(expected)}\n` + + `Received: ${printReceived(received)}`) ); }; diff --git a/packages/jest-matcher-utils/src/__tests__/__snapshots__/index.test.js.snap b/packages/jest-matcher-utils/src/__tests__/__snapshots__/index.test.js.snap index fb80b64d1896..68b90892609a 100644 --- a/packages/jest-matcher-utils/src/__tests__/__snapshots__/index.test.js.snap +++ b/packages/jest-matcher-utils/src/__tests__/__snapshots__/index.test.js.snap @@ -43,11 +43,6 @@ exports[`.stringify() reduces maxDepth if stringifying very large objects 2`] = exports[`.stringify() toJSON errors when comparing two objects 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - {\\"b\\": 1, \\"toJSON\\": [Function toJSON]} -Received: - {\\"a\\": 1, \\"toJSON\\": [Function toJSON]} - Difference: - Expected