From 17fb14ec0713e7f01708a296be3de952e2020d7b Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Wed, 9 Oct 2019 16:53:08 -0400 Subject: [PATCH 1/2] expect, jest-matcher-utils: Display change counts in annotation lines --- .../__snapshots__/failures.test.ts.snap | 8 +- .../__snapshots__/extend.test.js.snap | 16 +- .../__snapshots__/matchers.test.js.snap | 264 +++++++++--------- .../toThrowMatchers.test.ts.snap | 8 +- .../__snapshots__/index.test.ts.snap | 4 +- .../printDiffOrStringify.test.ts.snap | 8 +- packages/jest-matcher-utils/src/index.ts | 8 +- 7 files changed, 159 insertions(+), 157 deletions(-) diff --git a/e2e/__tests__/__snapshots__/failures.test.ts.snap b/e2e/__tests__/__snapshots__/failures.test.ts.snap index 9d29554a17bc..5c0197b587e7 100644 --- a/e2e/__tests__/__snapshots__/failures.test.ts.snap +++ b/e2e/__tests__/__snapshots__/failures.test.ts.snap @@ -288,8 +288,8 @@ FAIL __tests__/asyncFailures.test.js expect(received).resolves.toEqual(expected) // deep equality - - Expected - + Received + - Expected - 1 + + Received + 1 Object { - "baz": "bar", @@ -310,8 +310,8 @@ FAIL __tests__/asyncFailures.test.js expect(received).rejects.toEqual(expected) // deep equality - - Expected - + Received + - Expected - 1 + + Received + 1 Object { - "baz": "bar", diff --git a/packages/expect/src/__tests__/__snapshots__/extend.test.js.snap b/packages/expect/src/__tests__/__snapshots__/extend.test.js.snap index c912d6a569cf..b1b67afefea8 100644 --- a/packages/expect/src/__tests__/__snapshots__/extend.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/extend.test.js.snap @@ -3,8 +3,8 @@ exports[`defines asymmetric unary matchers 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { - "value": toBeDivisibleBy<2>, @@ -15,8 +15,8 @@ exports[`defines asymmetric unary matchers 1`] = ` exports[`defines asymmetric unary matchers that can be prefixed by not 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { - "value": not.toBeDivisibleBy<2>, @@ -27,8 +27,8 @@ exports[`defines asymmetric unary matchers that can be prefixed by not 1`] = ` exports[`defines asymmetric variadic matchers 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { - "value": toBeWithinRange<4, 11>, @@ -39,8 +39,8 @@ exports[`defines asymmetric variadic matchers 1`] = ` exports[`defines asymmetric variadic matchers that can be prefixed by not 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { - "value": not.toBeWithinRange<1, 3>, diff --git a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap index 29b749077cf7..f17d9dd254db 100644 --- a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap @@ -227,8 +227,8 @@ Received has value: undefined exports[`.toBe() does not crash on circular references 1`] = ` expect(received).toBe(expected) // Object.is equality -- Expected -+ Received +- Expected - 1 ++ Received + 3 - Object {} + Object { @@ -300,8 +300,8 @@ line string" 1`] = ` expect(received).toBe(expected) // Object.is equality -- Expected -+ Received +- Expected - 1 ++ Received + 2 - 3 + four @@ -321,8 +321,8 @@ exports[`.toBe() fails for: "with trailing space" and "without trailing space" 1`] = ` expect(received).toBe(expected) // Object.is equality -- Expected -+ Received +- Expected - 1 ++ Received + 2 - without trailing space + with @@ -364,8 +364,8 @@ exports[`.toBe() fails for: {"a": [Function a], "b": 2} and {"a": Any, If it should pass with deep equality, replace "toBe" with "toStrictEqual" -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { - "a": Any, @@ -386,8 +386,8 @@ Received: serializes to the same string exports[`.toBe() fails for: {"a": 1} and {"a": 5} 1`] = ` expect(received).toBe(expected) // Object.is equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { - "a": 5, @@ -400,8 +400,8 @@ exports[`.toBe() fails for: {"a": undefined, "b": 2} and {"b": 2} 1`] = ` If it should pass with deep equality, replace "toBe" with "toEqual" -- Expected -+ Received +- Expected - 0 ++ Received + 1 Object { + "a": undefined, @@ -2012,8 +2012,8 @@ exports[`.toEqual() {pass: false} expect("type TypeName = T extends Function : \\"object\\";") 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 3 ++ Received + 1 - type TypeName = T extends Function - ? "function" @@ -2024,8 +2024,8 @@ exports[`.toEqual() {pass: false} expect("type TypeName = T extends Function exports[`.toEqual() {pass: false} expect([1, 2]).toEqual([2, 1]) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Array [ - 2, @@ -2044,8 +2044,8 @@ Received: [1, 3] exports[`.toEqual() {pass: false} expect([1]).toEqual([2]) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Array [ - 2, @@ -2063,8 +2063,8 @@ Received: {"a": 1, "b": 2} exports[`.toEqual() {pass: false} expect({"a": 1}).toEqual({"a": 2}) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { - "a": 2, @@ -2075,8 +2075,8 @@ exports[`.toEqual() {pass: false} expect({"a": 1}).toEqual({"a": 2}) 1`] = ` exports[`.toEqual() {pass: false} expect({"a": 5}).toEqual({"b": 6}) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { - "b": 6, @@ -2087,8 +2087,8 @@ exports[`.toEqual() {pass: false} expect({"a": 5}).toEqual({"b": 6}) 1`] = ` exports[`.toEqual() {pass: false} expect({"nodeName": "div", "nodeType": 1}).toEqual({"nodeName": "p", "nodeType": 1}) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { - "nodeName": "p", @@ -2100,8 +2100,8 @@ exports[`.toEqual() {pass: false} expect({"nodeName": "div", "nodeType": 1}).toE exports[`.toEqual() {pass: false} expect({"target": {"nodeType": 1, "value": "a"}}).toEqual({"target": {"nodeType": 1, "value": "b"}}) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { "target": Object { @@ -2150,8 +2150,8 @@ Received: 5e-324 exports[`.toEqual() {pass: false} expect(Immutable.List [1, 2]).toEqual(Immutable.List [2, 1]) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Immutable.List [ - 2, @@ -2163,8 +2163,8 @@ exports[`.toEqual() {pass: false} expect(Immutable.List [1, 2]).toEqual(Immutabl exports[`.toEqual() {pass: false} expect(Immutable.List [1]).toEqual(Immutable.List [2]) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Immutable.List [ - 2, @@ -2175,8 +2175,8 @@ exports[`.toEqual() {pass: false} expect(Immutable.List [1]).toEqual(Immutable.L 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) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Immutable.Map { "1": Immutable.Map { @@ -2191,8 +2191,8 @@ exports[`.toEqual() {pass: false} expect(Immutable.Map {"1": Immutable.Map {"2": exports[`.toEqual() {pass: false} expect(Immutable.Map {"a": 0}).toEqual(Immutable.Map {"b": 0}) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Immutable.Map { - "b": 0, @@ -2203,8 +2203,8 @@ exports[`.toEqual() {pass: false} expect(Immutable.Map {"a": 0}).toEqual(Immutab exports[`.toEqual() {pass: false} expect(Immutable.Map {"v": 1}).toEqual(Immutable.Map {"v": 2}) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Immutable.Map { - "v": 2, @@ -2215,8 +2215,8 @@ exports[`.toEqual() {pass: false} expect(Immutable.Map {"v": 1}).toEqual(Immutab exports[`.toEqual() {pass: false} expect(Immutable.OrderedMap {1: "one", 2: "two"}).toEqual(Immutable.OrderedMap {2: "two", 1: "one"}) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Immutable.OrderedMap { - 2: "two", @@ -2228,8 +2228,8 @@ exports[`.toEqual() {pass: false} expect(Immutable.OrderedMap {1: "one", 2: "two exports[`.toEqual() {pass: false} expect(Immutable.OrderedSet [1, 2]).toEqual(Immutable.OrderedSet [2, 1]) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Immutable.OrderedSet [ - 2, @@ -2241,8 +2241,8 @@ exports[`.toEqual() {pass: false} expect(Immutable.OrderedSet [1, 2]).toEqual(Im exports[`.toEqual() {pass: false} expect(Immutable.Set [1, 2]).toEqual(Immutable.Set []) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 4 - Immutable.Set [] + Immutable.Set [ @@ -2254,8 +2254,8 @@ exports[`.toEqual() {pass: false} expect(Immutable.Set [1, 2]).toEqual(Immutable exports[`.toEqual() {pass: false} expect(Immutable.Set [1, 2]).toEqual(Immutable.Set [1, 2, 3]) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 0 Immutable.Set [ 1, @@ -2267,8 +2267,8 @@ exports[`.toEqual() {pass: false} expect(Immutable.Set [1, 2]).toEqual(Immutable exports[`.toEqual() {pass: false} expect(Map {"a" => 0}).toEqual(Map {"b" => 0}) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Map { - "b" => 0, @@ -2279,8 +2279,8 @@ exports[`.toEqual() {pass: false} expect(Map {"a" => 0}).toEqual(Map {"b" => 0}) exports[`.toEqual() {pass: false} expect(Map {"v" => 1}).toEqual(Map {"v" => 2}) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Map { - "v" => 2, @@ -2291,8 +2291,8 @@ exports[`.toEqual() {pass: false} expect(Map {"v" => 1}).toEqual(Map {"v" => 2}) exports[`.toEqual() {pass: false} expect(Map {["v"] => 1}).toEqual(Map {["v"] => 2}) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Map { Array [ @@ -2305,8 +2305,8 @@ exports[`.toEqual() {pass: false} expect(Map {["v"] => 1}).toEqual(Map {["v"] => exports[`.toEqual() {pass: false} expect(Map {[1] => Map {[1] => "one"}}).toEqual(Map {[1] => Map {[1] => "two"}}) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 @@ -2,8 +2,8 @@ Array [ @@ -2330,8 +2330,8 @@ Received: Map {} exports[`.toEqual() {pass: false} expect(Map {1 => "one", 2 => "two"}).toEqual(Map {1 => "one"}) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 0 ++ Received + 1 Map { 1 => "one", @@ -2342,8 +2342,8 @@ exports[`.toEqual() {pass: false} expect(Map {1 => "one", 2 => "two"}).toEqual(M exports[`.toEqual() {pass: false} expect(Set {[1], [2]}).toEqual(Set {[1], [2], [2]}) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 3 ++ Received + 0 @@ -3,9 +3,6 @@ 1, @@ -2360,8 +2360,8 @@ exports[`.toEqual() {pass: false} expect(Set {[1], [2]}).toEqual(Set {[1], [2], exports[`.toEqual() {pass: false} expect(Set {[1], [2]}).toEqual(Set {[1], [2], [3]}) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 3 ++ Received + 0 @@ -3,9 +3,6 @@ 1, @@ -2378,8 +2378,8 @@ exports[`.toEqual() {pass: false} expect(Set {[1], [2]}).toEqual(Set {[1], [2], exports[`.toEqual() {pass: false} expect(Set {1, 2}).toEqual(Set {}) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 4 - Set {} + Set { @@ -2391,8 +2391,8 @@ exports[`.toEqual() {pass: false} expect(Set {1, 2}).toEqual(Set {}) 1`] = ` exports[`.toEqual() {pass: false} expect(Set {1, 2}).toEqual(Set {1, 2, 3}) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 0 Set { 1, @@ -2404,8 +2404,8 @@ exports[`.toEqual() {pass: false} expect(Set {1, 2}).toEqual(Set {1, 2, 3}) 1`] exports[`.toEqual() {pass: false} expect(Set {Set {1}, Set {2}}).toEqual(Set {Set {1}, Set {3}}) 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Set { Set { @@ -3065,8 +3065,8 @@ exports[`.toHaveProperty() {pass: false} expect({"a": {"b": {"c": 5}}}).toHavePr Expected path: "a.b" -- Expected value -+ Received value +- Expected value - 1 ++ Received value + 1 Object { - "c": 4, @@ -3139,8 +3139,8 @@ Is good for you.") 1`] = ` Expected path: ["children", 0] -- Expected value -+ Received value +- Expected value - 3 ++ Received value + 3 - Roses are red, violets are blue. + Roses are red. @@ -3600,8 +3600,8 @@ Received: "Because TypeScript support in Babel is just transpilation, exports[`.toStrictEqual() displays substring diff for multiple lines 1`] = ` expect(received).toStrictEqual(expected) // deep equality -- Expected -+ Received +- Expected - 7 ++ Received + 7 - 69 | + 68 | @@ -3623,8 +3623,8 @@ exports[`.toStrictEqual() displays substring diff for multiple lines 1`] = ` exports[`.toStrictEqual() matches the expected snapshot when it fails 1`] = ` expect(received).toStrictEqual(expected) // deep equality -- Expected -+ Received +- Expected - 4 ++ Received + 1 Object { - "test": TestClassA { @@ -3645,8 +3645,8 @@ Expected: not {"test": {"a": 1, "b": 2}} exports[`toMatchObject() {pass: false} expect([0]).toMatchObject([-0]) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 1 ++ Received + 1 Array [ - -0, @@ -3657,8 +3657,8 @@ exports[`toMatchObject() {pass: false} expect([0]).toMatchObject([-0]) 1`] = ` exports[`toMatchObject() {pass: false} expect([1, 2, 3]).toMatchObject([1, 2, 2]) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 1 ++ Received + 1 Array [ 1, @@ -3671,8 +3671,8 @@ exports[`toMatchObject() {pass: false} expect([1, 2, 3]).toMatchObject([1, 2, 2] exports[`toMatchObject() {pass: false} expect([1, 2, 3]).toMatchObject([2, 3, 1]) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 1 ++ Received + 1 Array [ + 1, @@ -3685,8 +3685,8 @@ exports[`toMatchObject() {pass: false} expect([1, 2, 3]).toMatchObject([2, 3, 1] exports[`toMatchObject() {pass: false} expect([1, 2]).toMatchObject([1, 3]) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 1 ++ Received + 1 Array [ 1, @@ -3705,8 +3705,8 @@ Received: [Error: foo] exports[`toMatchObject() {pass: false} expect({"a": "a", "c": "d"}).toMatchObject({"a": Any}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { - "a": Any, @@ -3717,8 +3717,8 @@ exports[`toMatchObject() {pass: false} expect({"a": "a", "c": "d"}).toMatchObjec exports[`toMatchObject() {pass: false} expect({"a": "b", "c": "d"}).toMatchObject({"a": "b!", "c": "d"}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { - "a": "b!", @@ -3730,8 +3730,8 @@ exports[`toMatchObject() {pass: false} expect({"a": "b", "c": "d"}).toMatchObjec exports[`toMatchObject() {pass: false} expect({"a": "b", "c": "d"}).toMatchObject({"e": "b"}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 1 ++ Received + 2 Object { - "e": "b", @@ -3743,8 +3743,8 @@ exports[`toMatchObject() {pass: false} expect({"a": "b", "c": "d"}).toMatchObjec exports[`toMatchObject() {pass: false} expect({"a": "b", "t": {"x": {"r": "r"}, "z": "z"}}).toMatchObject({"a": "b", "t": {"z": [3]}}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 3 ++ Received + 1 Object { "a": "b", @@ -3760,8 +3760,8 @@ exports[`toMatchObject() {pass: false} expect({"a": "b", "t": {"x": {"r": "r"}, exports[`toMatchObject() {pass: false} expect({"a": "b", "t": {"x": {"r": "r"}, "z": "z"}}).toMatchObject({"t": {"l": {"r": "r"}}}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 1 ++ Received + 2 Object { "t": Object { @@ -3777,8 +3777,8 @@ exports[`toMatchObject() {pass: false} expect({"a": "b", "t": {"x": {"r": "r"}, exports[`toMatchObject() {pass: false} expect({"a": "b"}).toMatchObject({"c": "d"}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { - "c": "d", @@ -3789,8 +3789,8 @@ exports[`toMatchObject() {pass: false} expect({"a": "b"}).toMatchObject({"c": "d exports[`toMatchObject() {pass: false} expect({"a": [{"a": "a", "b": "b"}]}).toMatchObject({"a": [{"a": "c"}]}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { "a": Array [ @@ -3805,8 +3805,8 @@ exports[`toMatchObject() {pass: false} expect({"a": [{"a": "a", "b": "b"}]}).toM exports[`toMatchObject() {pass: false} expect({"a": [3, 4, "v"], "b": "b"}).toMatchObject({"a": ["v"]}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 0 ++ Received + 2 Object { "a": Array [ @@ -3820,8 +3820,8 @@ exports[`toMatchObject() {pass: false} expect({"a": [3, 4, "v"], "b": "b"}).toMa exports[`toMatchObject() {pass: false} expect({"a": [3, 4, 5], "b": "b"}).toMatchObject({"a": [3, 4, 5, 6]}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 1 ++ Received + 0 Object { "a": Array [ @@ -3836,8 +3836,8 @@ exports[`toMatchObject() {pass: false} expect({"a": [3, 4, 5], "b": "b"}).toMatc exports[`toMatchObject() {pass: false} expect({"a": [3, 4, 5], "b": "b"}).toMatchObject({"a": [3, 4]}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 0 ++ Received + 1 Object { "a": Array [ @@ -3851,8 +3851,8 @@ exports[`toMatchObject() {pass: false} expect({"a": [3, 4, 5], "b": "b"}).toMatc exports[`toMatchObject() {pass: false} expect({"a": [3, 4, 5], "b": "b"}).toMatchObject({"a": {"b": 4}}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 3 ++ Received + 5 Object { - "a": Object { @@ -3869,8 +3869,8 @@ exports[`toMatchObject() {pass: false} expect({"a": [3, 4, 5], "b": "b"}).toMatc exports[`toMatchObject() {pass: false} expect({"a": [3, 4, 5], "b": "b"}).toMatchObject({"a": {"b": Any}}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 3 ++ Received + 5 Object { - "a": Object { @@ -3887,8 +3887,8 @@ exports[`toMatchObject() {pass: false} expect({"a": [3, 4, 5], "b": "b"}).toMatc exports[`toMatchObject() {pass: false} expect({"a": 1, "b": 1, "c": 1, "d": {"e": {"f": 555}}}).toMatchObject({"d": {"e": {"f": 222}}}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { "d": Object { @@ -3903,8 +3903,8 @@ exports[`toMatchObject() {pass: false} expect({"a": 1, "b": 1, "c": 1, "d": {"e" exports[`toMatchObject() {pass: false} expect({"a": 2015-11-30T00:00:00.000Z, "b": "b"}).toMatchObject({"a": 2015-10-10T00:00:00.000Z}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { - "a": 2015-10-10T00:00:00.000Z, @@ -3915,8 +3915,8 @@ exports[`toMatchObject() {pass: false} expect({"a": 2015-11-30T00:00:00.000Z, "b exports[`toMatchObject() {pass: false} expect({"a": null, "b": "b"}).toMatchObject({"a": "4"}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { - "a": "4", @@ -3927,8 +3927,8 @@ exports[`toMatchObject() {pass: false} expect({"a": null, "b": "b"}).toMatchObje exports[`toMatchObject() {pass: false} expect({"a": null, "b": "b"}).toMatchObject({"a": undefined}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { - "a": undefined, @@ -3939,8 +3939,8 @@ exports[`toMatchObject() {pass: false} expect({"a": null, "b": "b"}).toMatchObje exports[`toMatchObject() {pass: false} expect({"a": undefined}).toMatchObject({"a": null}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { - "a": null, @@ -3951,8 +3951,8 @@ exports[`toMatchObject() {pass: false} expect({"a": undefined}).toMatchObject({" exports[`toMatchObject() {pass: false} expect({}).toMatchObject({"a": undefined}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 3 ++ Received + 1 - Object { - "a": undefined, @@ -3970,8 +3970,8 @@ Received: 2015-11-30T00:00:00.000Z exports[`toMatchObject() {pass: false} expect(Set {1, 2}).toMatchObject(Set {2}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 0 ++ Received + 1 Set { + 1, @@ -4128,8 +4128,8 @@ Received: Set {1, 2} exports[`toMatchObject() circular references simple circular references {pass: false} expect({"a": "hello", "ref": [Circular]}).toMatchObject({"a": "world", "ref": [Circular]}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { - "a": "world", @@ -4141,8 +4141,8 @@ exports[`toMatchObject() circular references simple circular references {pass: f exports[`toMatchObject() circular references simple circular references {pass: false} expect({"ref": "not a ref"}).toMatchObject({"a": "hello", "ref": [Circular]}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 2 ++ Received + 1 Object { - "a": "hello", @@ -4154,8 +4154,8 @@ exports[`toMatchObject() circular references simple circular references {pass: f exports[`toMatchObject() circular references simple circular references {pass: false} expect({}).toMatchObject({"a": "hello", "ref": [Circular]}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 4 ++ Received + 1 - Object { - "a": "hello", @@ -4180,8 +4180,8 @@ Received: {"a": "hello", "ref": [Circular]} exports[`toMatchObject() circular references transitive circular references {pass: false} expect({"a": "world", "nestedObj": {"parentObj": [Circular]}}).toMatchObject({"a": "hello", "nestedObj": {"parentObj": [Circular]}}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { - "a": "hello", @@ -4195,8 +4195,8 @@ exports[`toMatchObject() circular references transitive circular references {pas exports[`toMatchObject() circular references transitive circular references {pass: false} expect({"nestedObj": {"parentObj": "not the parent ref"}}).toMatchObject({"a": "hello", "nestedObj": {"parentObj": [Circular]}}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 2 ++ Received + 1 Object { - "a": "hello", @@ -4210,8 +4210,8 @@ exports[`toMatchObject() circular references transitive circular references {pas exports[`toMatchObject() circular references transitive circular references {pass: false} expect({}).toMatchObject({"a": "hello", "nestedObj": {"parentObj": [Circular]}}) 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 6 ++ Received + 1 - Object { - "a": "hello", @@ -4238,8 +4238,8 @@ Received: {"a": "hello", "nestedObj": {"parentObj": [Circular]}} exports[`toMatchObject() does not match properties up in the prototype chain 1`] = ` expect(received).toMatchObject(expected) -- Expected -+ Received +- Expected - 1 ++ Received + 0 Object { "other": "child", diff --git a/packages/expect/src/__tests__/__snapshots__/toThrowMatchers.test.ts.snap b/packages/expect/src/__tests__/__snapshots__/toThrowMatchers.test.ts.snap index 1298e5c60def..0b2df1702e07 100644 --- a/packages/expect/src/__tests__/__snapshots__/toThrowMatchers.test.ts.snap +++ b/packages/expect/src/__tests__/__snapshots__/toThrowMatchers.test.ts.snap @@ -164,8 +164,8 @@ Expected message: not "Invalid array length" exports[`toThrow error-message fail multiline diff highlight incorrect expected space 1`] = ` expect(received).toThrow(expected) -- Expected message -+ Received message +- Expected message - 1 ++ Received message + 1 - There is no route defined for key Settings. + There is no route defined for key Settings. @@ -472,8 +472,8 @@ Expected message: not "Invalid array length" exports[`toThrowError error-message fail multiline diff highlight incorrect expected space 1`] = ` expect(received).toThrowError(expected) -- Expected message -+ Received message +- Expected message - 1 ++ Received message + 1 - There is no route defined for key Settings. + There is no route defined for key Settings. diff --git a/packages/jest-matcher-utils/src/__tests__/__snapshots__/index.test.ts.snap b/packages/jest-matcher-utils/src/__tests__/__snapshots__/index.test.ts.snap index c930a2254670..449a8ac82a93 100644 --- a/packages/jest-matcher-utils/src/__tests__/__snapshots__/index.test.ts.snap +++ b/packages/jest-matcher-utils/src/__tests__/__snapshots__/index.test.ts.snap @@ -91,8 +91,8 @@ Expected has value: null exports[`stringify() toJSON errors when comparing two objects 1`] = ` expect(received).toEqual(expected) // deep equality -- Expected -+ Received +- Expected - 1 ++ Received + 1 Object { - "b": 1, diff --git a/packages/jest-matcher-utils/src/__tests__/__snapshots__/printDiffOrStringify.test.ts.snap b/packages/jest-matcher-utils/src/__tests__/__snapshots__/printDiffOrStringify.test.ts.snap index a7b07ed744fe..bb0566e91835 100644 --- a/packages/jest-matcher-utils/src/__tests__/__snapshots__/printDiffOrStringify.test.ts.snap +++ b/packages/jest-matcher-utils/src/__tests__/__snapshots__/printDiffOrStringify.test.ts.snap @@ -1,8 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`printDiffOrStringify expected and received are multi line with trailing spaces 1`] = ` -- Expected -+ Received +- Expected - 3 ++ Received + 3 - delete + insert @@ -29,8 +29,8 @@ Received: "" `; exports[`printDiffOrStringify has no common after clean up chaff multiline 1`] = ` -- Expected -+ Received +- Expected - 2 ++ Received + 2 - delete - two diff --git a/packages/jest-matcher-utils/src/index.ts b/packages/jest-matcher-utils/src/index.ts index c1526694b77d..8229292934b6 100644 --- a/packages/jest-matcher-utils/src/index.ts +++ b/packages/jest-matcher-utils/src/index.ts @@ -6,7 +6,7 @@ */ import chalk from 'chalk'; -import diffLinesUnified, { +import diffDefault, { DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, @@ -325,6 +325,7 @@ export const printDiffOrStringify = ( aAnnotation: expectedLabel, bAnnotation: receivedLabel, expand, + includeChangeCounts: true, }); } @@ -347,10 +348,11 @@ export const printDiffOrStringify = ( } if (isLineDiffable(expected, received)) { - const difference = diffLinesUnified(expected, received, { + const difference = diffDefault(expected, received, { aAnnotation: expectedLabel, bAnnotation: receivedLabel, expand, + includeChangeCounts: true, }); if ( @@ -390,7 +392,7 @@ const shouldPrintDiff = (actual: unknown, expected: unknown) => { }; export const diff = (a: any, b: any, options?: DiffOptions): string | null => - shouldPrintDiff(a, b) ? diffLinesUnified(a, b, options) : null; + shouldPrintDiff(a, b) ? diffDefault(a, b, options) : null; export const pluralize = (word: string, count: number) => (NUMBERS[count] || count) + ' ' + word + (count === 1 ? '' : 's'); From 8f9249dd473cacada85d23e6d7123cce644d87bd Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Wed, 9 Oct 2019 17:11:18 -0400 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a654ea7f9591..60010fe140fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - `[babel-plugin-jest-hoist]` Add `BigInt` to `WHITELISTED_IDENTIFIERS` ([#8382](https://github.com/facebook/jest/pull/8382)) - `[babel-preset-jest]` Add `@babel/plugin-syntax-bigint` ([#8382](https://github.com/facebook/jest/pull/8382)) - `[expect]` Add `BigInt` support to `toBeGreaterThan`, `toBeGreaterThanOrEqual`, `toBeLessThan` and `toBeLessThanOrEqual` ([#8382](https://github.com/facebook/jest/pull/8382)) +- `[expect, jest-matcher-utils]` Display change counts in annotation lines ([#9035](https://github.com/facebook/jest/pull/9035)) - `[jest-config]` Throw the full error message and stack when a Jest preset is missing a dependency ([#8924](https://github.com/facebook/jest/pull/8924)) - `[jest-config]` [**BREAKING**] Set default display name color based on runner ([#8689](https://github.com/facebook/jest/pull/8689)) - `[jest-diff]` Add options for colors and symbols ([#8841](https://github.com/facebook/jest/pull/8841))