From 9c1805c0c9fd37391a7b78d9139f378c659d11d7 Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 3 Nov 2018 08:49:48 -0500 Subject: [PATCH 1/7] Update toEqual failure message --- .../__snapshots__/matchers.test.js.snap | 21 +++++++++++++++++++ .../expect/src/__tests__/matchers.test.js | 10 +++++++++ packages/expect/src/matchers.js | 19 +++++++---------- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap index 5a3e468bb84b..f887ac3d2ef6 100644 --- a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap @@ -2739,6 +2739,27 @@ Received: undefined" `; +exports[`.toEqual() failure message matches the expected snapshot 1`] = ` +"expect(received).toEqual(expected) + +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`] = ` "expect(received).toHaveLength(length) diff --git a/packages/expect/src/__tests__/matchers.test.js b/packages/expect/src/__tests__/matchers.test.js index 344e451b55e4..ca4751bcfdbe 100644 --- a/packages/expect/src/__tests__/matchers.test.js +++ b/packages/expect/src/__tests__/matchers.test.js @@ -483,6 +483,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 4e9575213513..bb5c54d4767a 100644 --- a/packages/expect/src/matchers.js +++ b/packages/expect/src/matchers.js @@ -371,23 +371,20 @@ 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') + - '\n\n' + - `Expected value to equal:\n` + - ` ${printExpected(expected)}\n` + - `Received:\n` + - ` ${printReceived(received)}` + + matcherHint('.toEqual', undefined, undefined, { + isNot: this.isNot, + }) + (diffString && !oneline ? `\n\nDifference:\n\n${diffString}` : '') ); }; From e48ab173c9669e0e49fd468edc2a307b5b2091d1 Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 3 Nov 2018 09:12:12 -0500 Subject: [PATCH 2/7] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5744f75cd03..70ae7c86cfbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,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-mock]` [**BREAKING**] Fix bugs with mock/spy result tracking of recursive functions ([#6381](https://github.com/facebook/jest/pull/6381)) - `[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)) From a53843d69ec34e7c55b7c74abfaeb1b2896da90d Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 3 Nov 2018 12:07:07 -0500 Subject: [PATCH 3/7] Update failing snapshots --- .../__snapshots__/failures.test.js.snap | 15 - .../__snapshots__/extend.test.js.snap | 20 - .../__snapshots__/matchers.test.js.snap | 554 +++++------------- .../__snapshots__/index.test.js.snap | 5 - 4 files changed, 133 insertions(+), 461 deletions(-) diff --git a/e2e/__tests__/__snapshots__/failures.test.js.snap b/e2e/__tests__/__snapshots__/failures.test.js.snap index ab3f4c76b947..28f7cfd027ad 100644 --- a/e2e/__tests__/__snapshots__/failures.test.js.snap +++ b/e2e/__tests__/__snapshots__/failures.test.js.snap @@ -272,11 +272,6 @@ exports[`works with assertions in separate files 1`] = ` expect(received).toEqual(expected) - Expected value to equal: - 2 - Received: - 1 - 10 | 11 | module.exports = (one: any, two: any) => { > 12 | expect(one).toEqual(two); @@ -302,11 +297,6 @@ exports[`works with async failures 1`] = ` expect(received).toEqual(expected) - Expected value to equal: - {\\"baz\\": \\"bar\\"} - Received: - {\\"foo\\": \\"bar\\"} - Difference: - Expected @@ -331,11 +321,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 f887ac3d2ef6..11b8fa4a69a7 100644 --- a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap @@ -1702,103 +1702,58 @@ Received: 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\\"" -`; +exports[`.toEqual() {pass: false} expect("Eve").toEqual({"asymmetricMatch": [Function asymmetricMatch]}) 1`] = `"expect(received).toEqual(expected)"`; 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) - -Expected value to not equal: - StringMatching /bc/ -Received: - \\"abcd\\"" -`; - -exports[`.toEqual() {pass: false} expect("abd").toEqual(StringContaining "bc") 1`] = ` -"expect(received).toEqual(expected) +"expect(received).not.toEqual(expected) -Expected value to equal: - StringContaining \\"bc\\" -Received: - \\"abd\\"" +Expected: StringMatching /bc/ +Received: \\"abcd\\"" `; -exports[`.toEqual() {pass: false} expect("abd").toEqual(StringMatching /bc/i) 1`] = ` -"expect(received).toEqual(expected) +exports[`.toEqual() {pass: false} expect("abd").toEqual(StringContaining "bc") 1`] = `"expect(received).toEqual(expected)"`; -Expected value to equal: - StringMatching /bc/i -Received: - \\"abd\\"" -`; - -exports[`.toEqual() {pass: false} expect("banana").toEqual("apple") 1`] = ` -"expect(received).toEqual(expected) +exports[`.toEqual() {pass: false} expect("abd").toEqual(StringMatching /bc/i) 1`] = `"expect(received).toEqual(expected)"`; -Expected value to equal: - \\"apple\\" -Received: - \\"banana\\"" -`; +exports[`.toEqual() {pass: false} expect("banana").toEqual("apple") 1`] = `"expect(received).toEqual(expected)"`; 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 @@ -1814,11 +1769,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 @@ -1833,22 +1783,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 @@ -1861,40 +1804,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 @@ -1911,11 +1843,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 @@ -1928,22 +1855,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 @@ -1959,75 +1879,47 @@ 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." `; 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" -`; +exports[`.toEqual() {pass: false} expect(1).toEqual(2) 1`] = `"expect(received).toEqual(expected)"`; 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." `; 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 @@ -2041,22 +1933,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 @@ -2069,22 +1954,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 @@ -2103,11 +1981,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 @@ -2122,11 +1995,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 @@ -2139,49 +2007,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 @@ -2195,31 +2050,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 @@ -2233,40 +2079,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 @@ -2282,11 +2117,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 @@ -2302,11 +2132,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 @@ -2321,11 +2146,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 @@ -2340,11 +2160,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 @@ -2359,40 +2174,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 @@ -2411,62 +2215,44 @@ 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." `; 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 @@ -2479,40 +2265,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 @@ -2533,11 +2308,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 @@ -2556,49 +2326,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 @@ -2614,11 +2371,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 @@ -2632,22 +2384,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 @@ -2667,11 +2412,6 @@ 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." @@ -2680,64 +2420,36 @@ Difference: 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." `; 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" -`; +exports[`.toEqual() {pass: false} expect(true).toEqual(false) 1`] = `"expect(received).toEqual(expected)"`; exports[`.toEqual() {pass: false} expect(undefined).toEqual(Any) 1`] = ` "expect(received).toEqual(expected) -Expected value to equal: - Any -Received: - undefined - Difference: Comparing two different types of values. Expected function but received undefined." `; -exports[`.toEqual() {pass: false} expect(undefined).toEqual(Anything) 1`] = ` -"expect(received).toEqual(expected) - -Expected value to equal: - Anything -Received: - undefined" -`; +exports[`.toEqual() {pass: false} expect(undefined).toEqual(Anything) 1`] = `"expect(received).toEqual(expected)"`; exports[`.toEqual() failure message matches the expected snapshot 1`] = ` "expect(received).toEqual(expected) 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 7a8565648a34..618badfb8fd0 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 @@ -7,11 +7,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 From d316498fb39a45822a970beb159c9c6f32bff214 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 19 Nov 2018 13:30:41 -0600 Subject: [PATCH 4/7] Show one line reports --- .../__tests__/__snapshots__/matchers.test.js.snap | 12 +++++++++++- packages/expect/src/matchers.js | 4 +--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap index 11b8fa4a69a7..8a8d469a4cfd 100644 --- a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap @@ -1735,7 +1735,17 @@ exports[`.toEqual() {pass: false} expect("abd").toEqual(StringContaining "bc") 1 exports[`.toEqual() {pass: false} expect("abd").toEqual(StringMatching /bc/i) 1`] = `"expect(received).toEqual(expected)"`; -exports[`.toEqual() {pass: false} expect("banana").toEqual("apple") 1`] = `"expect(received).toEqual(expected)"`; +exports[`.toEqual() {pass: false} expect("banana").toEqual("apple") 1`] = ` +"expect(received).toEqual(expected) + +Difference: + +- Expected ++ Received + +- apple ++ banana" +`; exports[`.toEqual() {pass: false} expect([1, 2, 3]).not.toEqual(ArrayContaining [2, 3]) 1`] = ` "expect(received).not.toEqual(expected) diff --git a/packages/expect/src/matchers.js b/packages/expect/src/matchers.js index bb5c54d4767a..b1e6f7da6634 100644 --- a/packages/expect/src/matchers.js +++ b/packages/expect/src/matchers.js @@ -378,14 +378,12 @@ const matchers: MatchersObject = { `Expected: ${printExpected(expected)}\n` + `Received: ${printReceived(received)}` : () => { - const oneline = isOneline(expected, received); const diffString = diff(expected, received, {expand: this.expand}); return ( matcherHint('.toEqual', undefined, undefined, { isNot: this.isNot, - }) + - (diffString && !oneline ? `\n\nDifference:\n\n${diffString}` : '') + }) + (diffString ? `\n\nDifference:\n\n${diffString}` : '') ); }; From 09dbb4c8595a31f09985554e6222d04c8b4c69bc Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 19 Nov 2018 15:22:17 -0600 Subject: [PATCH 5/7] Update failure message when diffString is null --- .../__snapshots__/matchers.test.js.snap | 42 ++++++++++++++++--- packages/expect/src/matchers.js | 7 +++- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap index 8a8d469a4cfd..1b3906afacf7 100644 --- a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap @@ -1708,7 +1708,12 @@ Expected: {\\"asymmetricMatch\\": [Function asymmetricMatch]} Received: \\"Alice\\"" `; -exports[`.toEqual() {pass: false} expect("Eve").toEqual({"asymmetricMatch": [Function asymmetricMatch]}) 1`] = `"expect(received).toEqual(expected)"`; +exports[`.toEqual() {pass: false} expect("Eve").toEqual({"asymmetricMatch": [Function asymmetricMatch]}) 1`] = ` +"expect(received).toEqual(expected) + +Expected: {\\"asymmetricMatch\\": [Function asymmetricMatch]} +Received: \\"Eve\\"" +`; exports[`.toEqual() {pass: false} expect("abc").not.toEqual("abc") 1`] = ` "expect(received).not.toEqual(expected) @@ -1731,9 +1736,19 @@ Expected: StringMatching /bc/ Received: \\"abcd\\"" `; -exports[`.toEqual() {pass: false} expect("abd").toEqual(StringContaining "bc") 1`] = `"expect(received).toEqual(expected)"`; +exports[`.toEqual() {pass: false} expect("abd").toEqual(StringContaining "bc") 1`] = ` +"expect(received).toEqual(expected) -exports[`.toEqual() {pass: false} expect("abd").toEqual(StringMatching /bc/i) 1`] = `"expect(received).toEqual(expected)"`; +Expected: StringContaining \\"bc\\" +Received: \\"abd\\"" +`; + +exports[`.toEqual() {pass: false} expect("abd").toEqual(StringMatching /bc/i) 1`] = ` +"expect(received).toEqual(expected) + +Expected: StringMatching /bc/i +Received: \\"abd\\"" +`; exports[`.toEqual() {pass: false} expect("banana").toEqual("apple") 1`] = ` "expect(received).toEqual(expected) @@ -1910,7 +1925,12 @@ Expected: 1 Received: 1" `; -exports[`.toEqual() {pass: false} expect(1).toEqual(2) 1`] = `"expect(received).toEqual(expected)"`; +exports[`.toEqual() {pass: false} expect(1).toEqual(2) 1`] = ` +"expect(received).toEqual(expected) + +Expected: 2 +Received: 1" +`; exports[`.toEqual() {pass: false} expect(1).toEqual(ArrayContaining [1, 2]) 1`] = ` "expect(received).toEqual(expected) @@ -2449,7 +2469,12 @@ Expected: true Received: true" `; -exports[`.toEqual() {pass: false} expect(true).toEqual(false) 1`] = `"expect(received).toEqual(expected)"`; +exports[`.toEqual() {pass: false} expect(true).toEqual(false) 1`] = ` +"expect(received).toEqual(expected) + +Expected: false +Received: true" +`; exports[`.toEqual() {pass: false} expect(undefined).toEqual(Any) 1`] = ` "expect(received).toEqual(expected) @@ -2459,7 +2484,12 @@ Difference: Comparing two different types of values. Expected function but received undefined." `; -exports[`.toEqual() {pass: false} expect(undefined).toEqual(Anything) 1`] = `"expect(received).toEqual(expected)"`; +exports[`.toEqual() {pass: false} expect(undefined).toEqual(Anything) 1`] = ` +"expect(received).toEqual(expected) + +Expected: Anything +Received: undefined" +`; exports[`.toEqual() failure message matches the expected snapshot 1`] = ` "expect(received).toEqual(expected) diff --git a/packages/expect/src/matchers.js b/packages/expect/src/matchers.js index b1e6f7da6634..530b94843b80 100644 --- a/packages/expect/src/matchers.js +++ b/packages/expect/src/matchers.js @@ -383,7 +383,12 @@ const matchers: MatchersObject = { return ( matcherHint('.toEqual', undefined, undefined, { isNot: this.isNot, - }) + (diffString ? `\n\nDifference:\n\n${diffString}` : '') + }) + + '\n\n' + + (diffString + ? `Difference:\n\n${diffString}` + : `Expected: ${printExpected(expected)}\n` + + `Received: ${printReceived(received)}`) ); }; From 27bd7059c25ac74655585c02b1d6054e514a7467 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 19 Nov 2018 16:01:20 -0600 Subject: [PATCH 6/7] Update failing snapshot --- e2e/__tests__/__snapshots__/failures.test.js.snap | 3 +++ 1 file changed, 3 insertions(+) diff --git a/e2e/__tests__/__snapshots__/failures.test.js.snap b/e2e/__tests__/__snapshots__/failures.test.js.snap index 28f7cfd027ad..3414904b4709 100644 --- a/e2e/__tests__/__snapshots__/failures.test.js.snap +++ b/e2e/__tests__/__snapshots__/failures.test.js.snap @@ -272,6 +272,9 @@ exports[`works with assertions in separate files 1`] = ` expect(received).toEqual(expected) + Expected: 2 + Received: 1 + 10 | 11 | module.exports = (one: any, two: any) => { > 12 | expect(one).toEqual(two); From 2b9e208da1a91aba8810ecdc8d24339f595bd195 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 20 Nov 2018 09:42:25 -0600 Subject: [PATCH 7/7] Update failure message for jest-diff edge cases --- .../__snapshots__/matchers.test.js.snap | 30 ++++++++----------- packages/expect/src/matchers.js | 2 +- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap index 1b3906afacf7..074c095a1e95 100644 --- a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap @@ -1913,9 +1913,8 @@ Received: {}" exports[`.toEqual() {pass: false} expect(0).toEqual(-0) 1`] = ` "expect(received).toEqual(expected) -Difference: - -Compared values have no visual difference." +Expected: -0 +Received: 0" `; exports[`.toEqual() {pass: false} expect(1).not.toEqual(1) 1`] = ` @@ -1935,9 +1934,8 @@ Received: 1" exports[`.toEqual() {pass: false} expect(1).toEqual(ArrayContaining [1, 2]) 1`] = ` "expect(received).toEqual(expected) -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`] = ` @@ -2261,9 +2259,8 @@ Received: Map {}" exports[`.toEqual() {pass: false} expect(Map {}).toEqual(Set {}) 1`] = ` "expect(received).toEqual(expected) -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`] = ` @@ -2442,17 +2439,15 @@ Difference: exports[`.toEqual() {pass: false} expect(false).toEqual(ObjectContaining {"a": 2}) 1`] = ` "expect(received).toEqual(expected) -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) -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`] = ` @@ -2479,9 +2474,8 @@ Received: true" exports[`.toEqual() {pass: false} expect(undefined).toEqual(Any) 1`] = ` "expect(received).toEqual(expected) -Difference: - - Comparing two different types of values. Expected function but received undefined." +Expected: Any +Received: undefined" `; exports[`.toEqual() {pass: false} expect(undefined).toEqual(Anything) 1`] = ` diff --git a/packages/expect/src/matchers.js b/packages/expect/src/matchers.js index 530b94843b80..90f8c62a1594 100644 --- a/packages/expect/src/matchers.js +++ b/packages/expect/src/matchers.js @@ -385,7 +385,7 @@ const matchers: MatchersObject = { isNot: this.isNot, }) + '\n\n' + - (diffString + (diffString && diffString.includes('- Expect') ? `Difference:\n\n${diffString}` : `Expected: ${printExpected(expected)}\n` + `Received: ${printReceived(received)}`)