diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a39c5e145e7..00522ef3dbc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - `[expect]` Improve report when negative CalledWith assertion fails ([#8755](https://github.com/facebook/jest/pull/8755)) - `[expect]` Improve report when positive CalledWith assertion fails ([#8771](https://github.com/facebook/jest/pull/8771)) - `[expect]` Display equal values for ReturnedWith similar to CalledWith ([#8791](https://github.com/facebook/jest/pull/8791)) +- `[expect, jest-snapshot]` Change color from green for some args in matcher hints ([#8812](https://github.com/facebook/jest/pull/8812)) - `[jest-snapshot]` Highlight substring differences when matcher fails, part 3 ([#8569](https://github.com/facebook/jest/pull/8569)) - `[jest-core]` Improve report when snapshots are obsolete ([#8448](https://github.com/facebook/jest/pull/8665)) - `[jest-cli]` Improve chai support (with detailed output, to match jest exceptions) ([#8454](https://github.com/facebook/jest/pull/8454)) diff --git a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap index e50e796cb05f..45aa734410be 100644 --- a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap @@ -475,7 +475,7 @@ exports[`.toBeCloseTo() {pass: false} expect(-Infinity)toBeCloseTo( -1.23) 1`] = Expected: -1.23 Received: -Infinity -Expected precision: 2 +Expected precision: 2 Expected difference: < 0.005 Received difference: Infinity" `; @@ -486,7 +486,7 @@ exports[`.toBeCloseTo() {pass: false} expect(Infinity)toBeCloseTo( -Infinity) 1` Expected: -Infinity Received: Infinity -Expected precision: 2 +Expected precision: 2 Expected difference: < 0.005 Received difference: Infinity" `; @@ -497,7 +497,7 @@ exports[`.toBeCloseTo() {pass: false} expect(Infinity)toBeCloseTo( 1.23) 1`] = ` Expected: 1.23 Received: Infinity -Expected precision: 2 +Expected precision: 2 Expected difference: < 0.005 Received difference: Infinity" `; @@ -522,7 +522,7 @@ exports[`.toBeCloseTo() {pass: true} expect(0)toBeCloseTo( 0.001) 1`] = ` Expected: not 0.001 Received: 0 -Expected precision: 2 +Expected precision: 2 Expected difference: not < 0.005 Received difference: 0.001" `; @@ -533,7 +533,7 @@ exports[`.toBeCloseTo() {pass: true} expect(1.23)toBeCloseTo( 1.225) 1`] = ` Expected: not 1.225 Received: 1.23 -Expected precision: 2 +Expected precision: 2 Expected difference: not < 0.005 Received difference: 0.004999999999999893" `; @@ -544,7 +544,7 @@ exports[`.toBeCloseTo() {pass: true} expect(1.23)toBeCloseTo( 1.226) 1`] = ` Expected: not 1.226 Received: 1.23 -Expected precision: 2 +Expected precision: 2 Expected difference: not < 0.005 Received difference: 0.0040000000000000036" `; @@ -555,7 +555,7 @@ exports[`.toBeCloseTo() {pass: true} expect(1.23)toBeCloseTo( 1.229) 1`] = ` Expected: not 1.229 Received: 1.23 -Expected precision: 2 +Expected precision: 2 Expected difference: not < 0.005 Received difference: 0.0009999999999998899" `; @@ -566,7 +566,7 @@ exports[`.toBeCloseTo() {pass: true} expect(1.23)toBeCloseTo( 1.234) 1`] = ` Expected: not 1.234 Received: 1.23 -Expected precision: 2 +Expected precision: 2 Expected difference: not < 0.005 Received difference: 0.0040000000000000036" `; @@ -579,34 +579,34 @@ Expected: not Infinity `; exports[`.toBeCloseTo() accepts an optional precision argument: [0, 0.000004, 5] 1`] = ` -"expect(received).not.toBeCloseTo(expected, precision) +"expect(received).not.toBeCloseTo(expected, precision) Expected: not 0.000004 Received: 0 -Expected precision: 5 +Expected precision: 5 Expected difference: not < 0.000005 Received difference: 0.000004" `; exports[`.toBeCloseTo() accepts an optional precision argument: [0, 0.0001, 3] 1`] = ` -"expect(received).not.toBeCloseTo(expected, precision) +"expect(received).not.toBeCloseTo(expected, precision) Expected: not 0.0001 Received: 0 -Expected precision: 3 +Expected precision: 3 Expected difference: not < 0.0005 Received difference: 0.0001" `; exports[`.toBeCloseTo() accepts an optional precision argument: [0, 0.1, 0] 1`] = ` -"expect(received).not.toBeCloseTo(expected, precision) +"expect(received).not.toBeCloseTo(expected, precision) Expected: not 0.1 Received: 0 -Expected precision: 0 +Expected precision: 0 Expected difference: not < 0.5 Received difference: 0.1" `; @@ -617,7 +617,7 @@ exports[`.toBeCloseTo() throws: [0, 0.01] 1`] = ` Expected: 0.01 Received: 0 -Expected precision: 2 +Expected precision: 2 Expected difference: < 0.005 Received difference: 0.01" `; @@ -628,7 +628,7 @@ exports[`.toBeCloseTo() throws: [1, 1.23] 1`] = ` Expected: 1.23 Received: 1 -Expected precision: 2 +Expected precision: 2 Expected difference: < 0.005 Received difference: 0.22999999999999998" `; @@ -639,13 +639,13 @@ exports[`.toBeCloseTo() throws: [1.23, 1.2249999] 1`] = ` Expected: 1.2249999 Received: 1.23 -Expected precision: 2 +Expected precision: 2 Expected difference: < 0.005 Received difference: 0.005000099999999952" `; exports[`.toBeCloseTo() throws: Matcher error promise empty isNot false received 1`] = ` -"expect(received).toBeCloseTo(expected, precision) +"expect(received).toBeCloseTo(expected, precision) Matcher error: received value must be a number @@ -680,7 +680,7 @@ Received has value: Symbol(0.1)" `; exports[`.toBeCloseTo() throws: Matcher error promise resolves isNot false received 1`] = ` -"expect(received).resolves.toBeCloseTo(expected, precision) +"expect(received).resolves.toBeCloseTo(expected, precision) Matcher error: received value must be a number @@ -689,7 +689,7 @@ Received has value: false" `; exports[`.toBeCloseTo() throws: Matcher error promise resolves isNot true expected 1`] = ` -"expect(received).resolves.not.toBeCloseTo(expected, precision) +"expect(received).resolves.not.toBeCloseTo(expected, precision) Matcher error: expected value must be a number diff --git a/packages/expect/src/__tests__/__snapshots__/spyMatchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/spyMatchers.test.js.snap index 1fa46b12f5ea..1bf242fcd488 100644 --- a/packages/expect/src/__tests__/__snapshots__/spyMatchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/spyMatchers.test.js.snap @@ -273,7 +273,7 @@ Number of returns: 1" `; exports[`nthCalledWith includes the custom mock name in the error message 1`] = ` -"expect(named-mock).not.nthCalledWith(n, ...expected) +"expect(named-mock).not.nthCalledWith(n, ...expected) n: 1 Expected: not \\"foo\\", \\"bar\\" @@ -282,34 +282,34 @@ Number of calls: 1" `; exports[`nthCalledWith negative throw matcher error for n that is not integer 1`] = ` -"expect(received).not.nthCalledWith(n, ...expected) +"expect(received).not.nthCalledWith(n, ...expected) -Matcher error: n must be a positive integer +Matcher error: n must be a positive integer n has type: number -n has value: Infinity" +n has value: Infinity" `; exports[`nthCalledWith positive throw matcher error for n that is not integer 1`] = ` -"expect(received).nthCalledWith(n, ...expected) +"expect(received).nthCalledWith(n, ...expected) -Matcher error: n must be a positive integer +Matcher error: n must be a positive integer n has type: number -n has value: 0.1" +n has value: 0.1" `; exports[`nthCalledWith positive throw matcher error for n that is not positive integer 1`] = ` -"expect(received).nthCalledWith(n, ...expected) +"expect(received).nthCalledWith(n, ...expected) -Matcher error: n must be a positive integer +Matcher error: n must be a positive integer n has type: number -n has value: 0" +n has value: 0" `; exports[`nthCalledWith works only on spies or jest.fn 1`] = ` -"expect(received).nthCalledWith(n, ...expected) +"expect(received).nthCalledWith(n, ...expected) Matcher error: received value must be a mock or spy function @@ -318,7 +318,7 @@ Received has value: [Function fn]" `; exports[`nthCalledWith works when not called 1`] = ` -"expect(jest.fn()).nthCalledWith(n, ...expected) +"expect(jest.fn()).nthCalledWith(n, ...expected) n: 1 Expected: \\"foo\\", \\"bar\\" @@ -327,7 +327,7 @@ Number of calls: 0" `; exports[`nthCalledWith works with Immutable.js objects 1`] = ` -"expect(jest.fn()).not.nthCalledWith(n, ...expected) +"expect(jest.fn()).not.nthCalledWith(n, ...expected) n: 1 Expected: not Immutable.Map {\\"a\\": {\\"b\\": \\"c\\"}}, Immutable.Map {\\"a\\": {\\"b\\": \\"c\\"}} @@ -336,7 +336,7 @@ Number of calls: 1" `; exports[`nthCalledWith works with Map 1`] = ` -"expect(jest.fn()).not.nthCalledWith(n, ...expected) +"expect(jest.fn()).not.nthCalledWith(n, ...expected) n: 1 Expected: not Map {1 => 2, 2 => 1} @@ -345,7 +345,7 @@ Number of calls: 1" `; exports[`nthCalledWith works with Map 2`] = ` -"expect(jest.fn()).nthCalledWith(n, ...expected) +"expect(jest.fn()).nthCalledWith(n, ...expected) n: 1 - Expected @@ -362,7 +362,7 @@ Number of calls: 1" `; exports[`nthCalledWith works with Set 1`] = ` -"expect(jest.fn()).not.nthCalledWith(n, ...expected) +"expect(jest.fn()).not.nthCalledWith(n, ...expected) n: 1 Expected: not Set {1, 2} @@ -371,7 +371,7 @@ Number of calls: 1" `; exports[`nthCalledWith works with Set 2`] = ` -"expect(jest.fn()).nthCalledWith(n, ...expected) +"expect(jest.fn()).nthCalledWith(n, ...expected) n: 1 - Expected @@ -388,7 +388,7 @@ Number of calls: 1" `; exports[`nthCalledWith works with arguments that don't match 1`] = ` -"expect(jest.fn()).nthCalledWith(n, ...expected) +"expect(jest.fn()).nthCalledWith(n, ...expected) n: 1 Expected: \\"foo\\", \\"bar\\" @@ -398,7 +398,7 @@ Number of calls: 1" `; exports[`nthCalledWith works with arguments that match 1`] = ` -"expect(jest.fn()).not.nthCalledWith(n, ...expected) +"expect(jest.fn()).not.nthCalledWith(n, ...expected) n: 1 Expected: not \\"foo\\", \\"bar\\" @@ -407,7 +407,7 @@ Number of calls: 1" `; exports[`nthCalledWith works with three calls 1`] = ` -"expect(jest.fn()).not.nthCalledWith(n, ...expected) +"expect(jest.fn()).not.nthCalledWith(n, ...expected) n: 1 Expected: not \\"foo1\\", \\"bar\\" @@ -419,7 +419,7 @@ Number of calls: 3" `; exports[`nthCalledWith works with trailing undefined arguments 1`] = ` -"expect(jest.fn()).nthCalledWith(n, ...expected) +"expect(jest.fn()).nthCalledWith(n, ...expected) n: 1 Expected: \\"foo\\" @@ -429,7 +429,7 @@ Number of calls: 1" `; exports[`nthReturnedWith a call that throws is not considered to have returned 1`] = ` -"expect(jest.fn()).nthReturnedWith(n, expected) +"expect(jest.fn()).nthReturnedWith(n, expected) n: 1 Expected: undefined @@ -440,7 +440,7 @@ Number of calls: 1" `; exports[`nthReturnedWith a call that throws undefined is not considered to have returned 1`] = ` -"expect(jest.fn()).nthReturnedWith(n, expected) +"expect(jest.fn()).nthReturnedWith(n, expected) n: 1 Expected: undefined @@ -451,7 +451,7 @@ Number of calls: 1" `; exports[`nthReturnedWith includes the custom mock name in the error message 1`] = ` -"expect(named-mock).nthReturnedWith(n, expected) +"expect(named-mock).nthReturnedWith(n, expected) n: 1 Expected: \\"foo\\" @@ -460,7 +460,7 @@ Number of returns: 0" `; exports[`nthReturnedWith nthReturnedWith incomplete recursive calls are handled properly 1`] = ` -"expect(jest.fn()).nthReturnedWith(n, expected) +"expect(jest.fn()).nthReturnedWith(n, expected) n: 1 Expected: 6 @@ -473,7 +473,7 @@ Number of calls: 4" `; exports[`nthReturnedWith nthReturnedWith incomplete recursive calls are handled properly 2`] = ` -"expect(jest.fn()).nthReturnedWith(n, expected) +"expect(jest.fn()).nthReturnedWith(n, expected) n: 2 Expected: 3 @@ -487,7 +487,7 @@ Number of calls: 4" `; exports[`nthReturnedWith nthReturnedWith incomplete recursive calls are handled properly 3`] = ` -"expect(jest.fn()).not.nthReturnedWith(n, expected) +"expect(jest.fn()).not.nthReturnedWith(n, expected) n: 3 Expected: not 1 @@ -501,7 +501,7 @@ Number of calls: 4" `; exports[`nthReturnedWith nthReturnedWith incomplete recursive calls are handled properly 4`] = ` -"expect(jest.fn()).not.nthReturnedWith(n, expected) +"expect(jest.fn()).not.nthReturnedWith(n, expected) n: 4 Expected: not 0 @@ -514,33 +514,33 @@ Number of calls: 4" `; exports[`nthReturnedWith nthReturnedWith negative throw matcher error for n that is not number 1`] = ` -"expect(received).not.nthReturnedWith(n, expected) +"expect(received).not.nthReturnedWith(n, expected) -Matcher error: n must be a positive integer +Matcher error: n must be a positive integer -n has value: undefined" +n has value: undefined" `; exports[`nthReturnedWith nthReturnedWith positive throw matcher error for n that is not integer 1`] = ` -"expect(received).nthReturnedWith(n, expected) +"expect(received).nthReturnedWith(n, expected) -Matcher error: n must be a positive integer +Matcher error: n must be a positive integer n has type: number -n has value: 0.1" +n has value: 0.1" `; exports[`nthReturnedWith nthReturnedWith positive throw matcher error for n that is not positive integer 1`] = ` -"expect(received).nthReturnedWith(n, expected) +"expect(received).nthReturnedWith(n, expected) -Matcher error: n must be a positive integer +Matcher error: n must be a positive integer n has type: number -n has value: 0" +n has value: 0" `; exports[`nthReturnedWith nthReturnedWith should reject nth value greater than number of calls 1`] = ` -"expect(jest.fn()).nthReturnedWith(n, expected) +"expect(jest.fn()).nthReturnedWith(n, expected) n: 4 Expected: \\"foo\\" @@ -551,7 +551,7 @@ Number of returns: 3" `; exports[`nthReturnedWith nthReturnedWith should replace 1st, 2nd, 3rd with first, second, third 1`] = ` -"expect(jest.fn()).nthReturnedWith(n, expected) +"expect(jest.fn()).nthReturnedWith(n, expected) n: 1 Expected: \\"bar1\\" @@ -563,7 +563,7 @@ Number of returns: 3" `; exports[`nthReturnedWith nthReturnedWith should replace 1st, 2nd, 3rd with first, second, third 2`] = ` -"expect(jest.fn()).not.nthReturnedWith(n, expected) +"expect(jest.fn()).not.nthReturnedWith(n, expected) n: 1 Expected: not \\"foo1\\" @@ -575,7 +575,7 @@ Number of returns: 3" `; exports[`nthReturnedWith nthReturnedWith works with three calls 1`] = ` -"expect(jest.fn()).not.nthReturnedWith(n, expected) +"expect(jest.fn()).not.nthReturnedWith(n, expected) n: 1 Expected: not \\"foo1\\" @@ -587,7 +587,7 @@ Number of returns: 3" `; exports[`nthReturnedWith works only on spies or jest.fn 1`] = ` -"expect(received).nthReturnedWith(n, expected) +"expect(received).nthReturnedWith(n, expected) Matcher error: received value must be a mock function @@ -596,7 +596,7 @@ Received has value: [Function fn]" `; exports[`nthReturnedWith works when not called 1`] = ` -"expect(jest.fn()).nthReturnedWith(n, expected) +"expect(jest.fn()).nthReturnedWith(n, expected) n: 1 Expected: \\"foo\\" @@ -605,7 +605,7 @@ Number of returns: 0" `; exports[`nthReturnedWith works with Immutable.js objects directly created 1`] = ` -"expect(jest.fn()).not.nthReturnedWith(n, expected) +"expect(jest.fn()).not.nthReturnedWith(n, expected) n: 1 Expected: not Immutable.Map {\\"a\\": {\\"b\\": \\"c\\"}} @@ -614,7 +614,7 @@ Number of returns: 1" `; exports[`nthReturnedWith works with Immutable.js objects indirectly created 1`] = ` -"expect(jest.fn()).not.nthReturnedWith(n, expected) +"expect(jest.fn()).not.nthReturnedWith(n, expected) n: 1 Expected: not Immutable.Map {\\"a\\": {\\"b\\": \\"c\\"}} @@ -623,7 +623,7 @@ Number of returns: 1" `; exports[`nthReturnedWith works with Map 1`] = ` -"expect(jest.fn()).not.nthReturnedWith(n, expected) +"expect(jest.fn()).not.nthReturnedWith(n, expected) n: 1 Expected: not Map {1 => 2, 2 => 1} @@ -632,7 +632,7 @@ Number of returns: 1" `; exports[`nthReturnedWith works with Map 2`] = ` -"expect(jest.fn()).nthReturnedWith(n, expected) +"expect(jest.fn()).nthReturnedWith(n, expected) n: 1 Expected: Map {\\"a\\" => \\"b\\", \\"b\\" => \\"a\\"} @@ -642,7 +642,7 @@ Number of returns: 1" `; exports[`nthReturnedWith works with Set 1`] = ` -"expect(jest.fn()).not.nthReturnedWith(n, expected) +"expect(jest.fn()).not.nthReturnedWith(n, expected) n: 1 Expected: not Set {1, 2} @@ -651,7 +651,7 @@ Number of returns: 1" `; exports[`nthReturnedWith works with Set 2`] = ` -"expect(jest.fn()).nthReturnedWith(n, expected) +"expect(jest.fn()).nthReturnedWith(n, expected) n: 1 Expected: Set {3, 4} @@ -661,7 +661,7 @@ Number of returns: 1" `; exports[`nthReturnedWith works with argument that does match 1`] = ` -"expect(jest.fn()).not.nthReturnedWith(n, expected) +"expect(jest.fn()).not.nthReturnedWith(n, expected) n: 1 Expected: not \\"foo\\" @@ -670,7 +670,7 @@ Number of returns: 1" `; exports[`nthReturnedWith works with argument that does not match 1`] = ` -"expect(jest.fn()).nthReturnedWith(n, expected) +"expect(jest.fn()).nthReturnedWith(n, expected) n: 1 Expected: \\"bar\\" @@ -680,7 +680,7 @@ Number of returns: 1" `; exports[`nthReturnedWith works with undefined 1`] = ` -"expect(jest.fn()).not.nthReturnedWith(n, expected) +"expect(jest.fn()).not.nthReturnedWith(n, expected) n: 1 Expected: not undefined @@ -1468,7 +1468,7 @@ Number of calls: 1" `; exports[`toHaveBeenNthCalledWith includes the custom mock name in the error message 1`] = ` -"expect(named-mock).not.toHaveBeenNthCalledWith(n, ...expected) +"expect(named-mock).not.toHaveBeenNthCalledWith(n, ...expected) n: 1 Expected: not \\"foo\\", \\"bar\\" @@ -1477,34 +1477,34 @@ Number of calls: 1" `; exports[`toHaveBeenNthCalledWith negative throw matcher error for n that is not integer 1`] = ` -"expect(received).not.toHaveBeenNthCalledWith(n, ...expected) +"expect(received).not.toHaveBeenNthCalledWith(n, ...expected) -Matcher error: n must be a positive integer +Matcher error: n must be a positive integer n has type: number -n has value: Infinity" +n has value: Infinity" `; exports[`toHaveBeenNthCalledWith positive throw matcher error for n that is not integer 1`] = ` -"expect(received).toHaveBeenNthCalledWith(n, ...expected) +"expect(received).toHaveBeenNthCalledWith(n, ...expected) -Matcher error: n must be a positive integer +Matcher error: n must be a positive integer n has type: number -n has value: 0.1" +n has value: 0.1" `; exports[`toHaveBeenNthCalledWith positive throw matcher error for n that is not positive integer 1`] = ` -"expect(received).toHaveBeenNthCalledWith(n, ...expected) +"expect(received).toHaveBeenNthCalledWith(n, ...expected) -Matcher error: n must be a positive integer +Matcher error: n must be a positive integer n has type: number -n has value: 0" +n has value: 0" `; exports[`toHaveBeenNthCalledWith works only on spies or jest.fn 1`] = ` -"expect(received).toHaveBeenNthCalledWith(n, ...expected) +"expect(received).toHaveBeenNthCalledWith(n, ...expected) Matcher error: received value must be a mock or spy function @@ -1513,7 +1513,7 @@ Received has value: [Function fn]" `; exports[`toHaveBeenNthCalledWith works when not called 1`] = ` -"expect(jest.fn()).toHaveBeenNthCalledWith(n, ...expected) +"expect(jest.fn()).toHaveBeenNthCalledWith(n, ...expected) n: 1 Expected: \\"foo\\", \\"bar\\" @@ -1522,7 +1522,7 @@ Number of calls: 0" `; exports[`toHaveBeenNthCalledWith works with Immutable.js objects 1`] = ` -"expect(jest.fn()).not.toHaveBeenNthCalledWith(n, ...expected) +"expect(jest.fn()).not.toHaveBeenNthCalledWith(n, ...expected) n: 1 Expected: not Immutable.Map {\\"a\\": {\\"b\\": \\"c\\"}}, Immutable.Map {\\"a\\": {\\"b\\": \\"c\\"}} @@ -1531,7 +1531,7 @@ Number of calls: 1" `; exports[`toHaveBeenNthCalledWith works with Map 1`] = ` -"expect(jest.fn()).not.toHaveBeenNthCalledWith(n, ...expected) +"expect(jest.fn()).not.toHaveBeenNthCalledWith(n, ...expected) n: 1 Expected: not Map {1 => 2, 2 => 1} @@ -1540,7 +1540,7 @@ Number of calls: 1" `; exports[`toHaveBeenNthCalledWith works with Map 2`] = ` -"expect(jest.fn()).toHaveBeenNthCalledWith(n, ...expected) +"expect(jest.fn()).toHaveBeenNthCalledWith(n, ...expected) n: 1 - Expected @@ -1557,7 +1557,7 @@ Number of calls: 1" `; exports[`toHaveBeenNthCalledWith works with Set 1`] = ` -"expect(jest.fn()).not.toHaveBeenNthCalledWith(n, ...expected) +"expect(jest.fn()).not.toHaveBeenNthCalledWith(n, ...expected) n: 1 Expected: not Set {1, 2} @@ -1566,7 +1566,7 @@ Number of calls: 1" `; exports[`toHaveBeenNthCalledWith works with Set 2`] = ` -"expect(jest.fn()).toHaveBeenNthCalledWith(n, ...expected) +"expect(jest.fn()).toHaveBeenNthCalledWith(n, ...expected) n: 1 - Expected @@ -1583,7 +1583,7 @@ Number of calls: 1" `; exports[`toHaveBeenNthCalledWith works with arguments that don't match 1`] = ` -"expect(jest.fn()).toHaveBeenNthCalledWith(n, ...expected) +"expect(jest.fn()).toHaveBeenNthCalledWith(n, ...expected) n: 1 Expected: \\"foo\\", \\"bar\\" @@ -1593,7 +1593,7 @@ Number of calls: 1" `; exports[`toHaveBeenNthCalledWith works with arguments that match 1`] = ` -"expect(jest.fn()).not.toHaveBeenNthCalledWith(n, ...expected) +"expect(jest.fn()).not.toHaveBeenNthCalledWith(n, ...expected) n: 1 Expected: not \\"foo\\", \\"bar\\" @@ -1602,7 +1602,7 @@ Number of calls: 1" `; exports[`toHaveBeenNthCalledWith works with three calls 1`] = ` -"expect(jest.fn()).not.toHaveBeenNthCalledWith(n, ...expected) +"expect(jest.fn()).not.toHaveBeenNthCalledWith(n, ...expected) n: 1 Expected: not \\"foo1\\", \\"bar\\" @@ -1614,7 +1614,7 @@ Number of calls: 3" `; exports[`toHaveBeenNthCalledWith works with trailing undefined arguments 1`] = ` -"expect(jest.fn()).toHaveBeenNthCalledWith(n, ...expected) +"expect(jest.fn()).toHaveBeenNthCalledWith(n, ...expected) n: 1 Expected: \\"foo\\" @@ -1767,7 +1767,7 @@ Number of returns: 1" `; exports[`toHaveNthReturnedWith a call that throws is not considered to have returned 1`] = ` -"expect(jest.fn()).toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).toHaveNthReturnedWith(n, expected) n: 1 Expected: undefined @@ -1778,7 +1778,7 @@ Number of calls: 1" `; exports[`toHaveNthReturnedWith a call that throws undefined is not considered to have returned 1`] = ` -"expect(jest.fn()).toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).toHaveNthReturnedWith(n, expected) n: 1 Expected: undefined @@ -1789,7 +1789,7 @@ Number of calls: 1" `; exports[`toHaveNthReturnedWith includes the custom mock name in the error message 1`] = ` -"expect(named-mock).toHaveNthReturnedWith(n, expected) +"expect(named-mock).toHaveNthReturnedWith(n, expected) n: 1 Expected: \\"foo\\" @@ -1798,7 +1798,7 @@ Number of returns: 0" `; exports[`toHaveNthReturnedWith nthReturnedWith incomplete recursive calls are handled properly 1`] = ` -"expect(jest.fn()).toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).toHaveNthReturnedWith(n, expected) n: 1 Expected: 6 @@ -1811,7 +1811,7 @@ Number of calls: 4" `; exports[`toHaveNthReturnedWith nthReturnedWith incomplete recursive calls are handled properly 2`] = ` -"expect(jest.fn()).toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).toHaveNthReturnedWith(n, expected) n: 2 Expected: 3 @@ -1825,7 +1825,7 @@ Number of calls: 4" `; exports[`toHaveNthReturnedWith nthReturnedWith incomplete recursive calls are handled properly 3`] = ` -"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) n: 3 Expected: not 1 @@ -1839,7 +1839,7 @@ Number of calls: 4" `; exports[`toHaveNthReturnedWith nthReturnedWith incomplete recursive calls are handled properly 4`] = ` -"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) n: 4 Expected: not 0 @@ -1852,33 +1852,33 @@ Number of calls: 4" `; exports[`toHaveNthReturnedWith nthReturnedWith negative throw matcher error for n that is not number 1`] = ` -"expect(received).not.toHaveNthReturnedWith(n, expected) +"expect(received).not.toHaveNthReturnedWith(n, expected) -Matcher error: n must be a positive integer +Matcher error: n must be a positive integer -n has value: undefined" +n has value: undefined" `; exports[`toHaveNthReturnedWith nthReturnedWith positive throw matcher error for n that is not integer 1`] = ` -"expect(received).toHaveNthReturnedWith(n, expected) +"expect(received).toHaveNthReturnedWith(n, expected) -Matcher error: n must be a positive integer +Matcher error: n must be a positive integer n has type: number -n has value: 0.1" +n has value: 0.1" `; exports[`toHaveNthReturnedWith nthReturnedWith positive throw matcher error for n that is not positive integer 1`] = ` -"expect(received).toHaveNthReturnedWith(n, expected) +"expect(received).toHaveNthReturnedWith(n, expected) -Matcher error: n must be a positive integer +Matcher error: n must be a positive integer n has type: number -n has value: 0" +n has value: 0" `; exports[`toHaveNthReturnedWith nthReturnedWith should reject nth value greater than number of calls 1`] = ` -"expect(jest.fn()).toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).toHaveNthReturnedWith(n, expected) n: 4 Expected: \\"foo\\" @@ -1889,7 +1889,7 @@ Number of returns: 3" `; exports[`toHaveNthReturnedWith nthReturnedWith should replace 1st, 2nd, 3rd with first, second, third 1`] = ` -"expect(jest.fn()).toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).toHaveNthReturnedWith(n, expected) n: 1 Expected: \\"bar1\\" @@ -1901,7 +1901,7 @@ Number of returns: 3" `; exports[`toHaveNthReturnedWith nthReturnedWith should replace 1st, 2nd, 3rd with first, second, third 2`] = ` -"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) n: 1 Expected: not \\"foo1\\" @@ -1913,7 +1913,7 @@ Number of returns: 3" `; exports[`toHaveNthReturnedWith nthReturnedWith works with three calls 1`] = ` -"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) n: 1 Expected: not \\"foo1\\" @@ -1925,7 +1925,7 @@ Number of returns: 3" `; exports[`toHaveNthReturnedWith works only on spies or jest.fn 1`] = ` -"expect(received).toHaveNthReturnedWith(n, expected) +"expect(received).toHaveNthReturnedWith(n, expected) Matcher error: received value must be a mock function @@ -1934,7 +1934,7 @@ Received has value: [Function fn]" `; exports[`toHaveNthReturnedWith works when not called 1`] = ` -"expect(jest.fn()).toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).toHaveNthReturnedWith(n, expected) n: 1 Expected: \\"foo\\" @@ -1943,7 +1943,7 @@ Number of returns: 0" `; exports[`toHaveNthReturnedWith works with Immutable.js objects directly created 1`] = ` -"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) n: 1 Expected: not Immutable.Map {\\"a\\": {\\"b\\": \\"c\\"}} @@ -1952,7 +1952,7 @@ Number of returns: 1" `; exports[`toHaveNthReturnedWith works with Immutable.js objects indirectly created 1`] = ` -"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) n: 1 Expected: not Immutable.Map {\\"a\\": {\\"b\\": \\"c\\"}} @@ -1961,7 +1961,7 @@ Number of returns: 1" `; exports[`toHaveNthReturnedWith works with Map 1`] = ` -"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) n: 1 Expected: not Map {1 => 2, 2 => 1} @@ -1970,7 +1970,7 @@ Number of returns: 1" `; exports[`toHaveNthReturnedWith works with Map 2`] = ` -"expect(jest.fn()).toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).toHaveNthReturnedWith(n, expected) n: 1 Expected: Map {\\"a\\" => \\"b\\", \\"b\\" => \\"a\\"} @@ -1980,7 +1980,7 @@ Number of returns: 1" `; exports[`toHaveNthReturnedWith works with Set 1`] = ` -"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) n: 1 Expected: not Set {1, 2} @@ -1989,7 +1989,7 @@ Number of returns: 1" `; exports[`toHaveNthReturnedWith works with Set 2`] = ` -"expect(jest.fn()).toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).toHaveNthReturnedWith(n, expected) n: 1 Expected: Set {3, 4} @@ -1999,7 +1999,7 @@ Number of returns: 1" `; exports[`toHaveNthReturnedWith works with argument that does match 1`] = ` -"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) n: 1 Expected: not \\"foo\\" @@ -2008,7 +2008,7 @@ Number of returns: 1" `; exports[`toHaveNthReturnedWith works with argument that does not match 1`] = ` -"expect(jest.fn()).toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).toHaveNthReturnedWith(n, expected) n: 1 Expected: \\"bar\\" @@ -2018,7 +2018,7 @@ Number of returns: 1" `; exports[`toHaveNthReturnedWith works with undefined 1`] = ` -"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) +"expect(jest.fn()).not.toHaveNthReturnedWith(n, expected) n: 1 Expected: not undefined diff --git a/packages/expect/src/matchers.ts b/packages/expect/src/matchers.ts index 52a8c9fe7e4f..828d6b2c64d4 100644 --- a/packages/expect/src/matchers.ts +++ b/packages/expect/src/matchers.ts @@ -133,6 +133,7 @@ const matchers: MatchersObject = { isNot: this.isNot, promise: this.promise, secondArgument, + secondArgumentColor: (arg: string) => arg, }; ensureNumbers(received, expected, matcherName, options); @@ -159,7 +160,7 @@ const matchers: MatchersObject = { ? '' : `Received: ${printReceived(received)}\n` + '\n' + - `Expected precision: ${printExpected(precision)}\n` + + `Expected precision: ${stringify(precision)}\n` + `Expected difference: not < ${printExpected(expectedDiff)}\n` + `Received difference: ${printReceived(receivedDiff)}`) : () => @@ -168,7 +169,7 @@ const matchers: MatchersObject = { `Expected: ${printExpected(expected)}\n` + `Received: ${printReceived(received)}\n` + '\n' + - `Expected precision: ${printExpected(precision)}\n` + + `Expected precision: ${stringify(precision)}\n` + `Expected difference: < ${printExpected(expectedDiff)}\n` + `Received difference: ${printReceived(receivedDiff)}`; diff --git a/packages/expect/src/spyMatchers.ts b/packages/expect/src/spyMatchers.ts index 0a37636fc64a..86425155357d 100644 --- a/packages/expect/src/spyMatchers.ts +++ b/packages/expect/src/spyMatchers.ts @@ -867,6 +867,7 @@ const createNthCalledWithMatcher = (matcherName: string) => ): SyncExpectationResult { const expectedArgument = 'n'; const options: MatcherHintOptions = { + expectedColor: (arg: string) => arg, isNot: this.isNot, promise: this.promise, secondArgument: '...expected', @@ -877,8 +878,8 @@ const createNthCalledWithMatcher = (matcherName: string) => throw new Error( matcherErrorMessage( matcherHint(matcherName, undefined, expectedArgument, options), - `${EXPECTED_COLOR(expectedArgument)} must be a positive integer`, - printWithType(expectedArgument, nth, printExpected), + `${expectedArgument} must be a positive integer`, + printWithType(expectedArgument, nth, stringify), ), ); } @@ -996,6 +997,7 @@ const createNthReturnedWithMatcher = (matcherName: string) => ): SyncExpectationResult { const expectedArgument = 'n'; const options: MatcherHintOptions = { + expectedColor: (arg: string) => arg, isNot: this.isNot, promise: this.promise, secondArgument: 'expected', @@ -1006,8 +1008,8 @@ const createNthReturnedWithMatcher = (matcherName: string) => throw new Error( matcherErrorMessage( matcherHint(matcherName, undefined, expectedArgument, options), - `${EXPECTED_COLOR(expectedArgument)} must be a positive integer`, - printWithType(expectedArgument, nth, printExpected), + `${expectedArgument} must be a positive integer`, + printWithType(expectedArgument, nth, stringify), ), ); } diff --git a/packages/jest-snapshot/src/index.ts b/packages/jest-snapshot/src/index.ts index a6de3a1a9ddd..6745dc99658c 100644 --- a/packages/jest-snapshot/src/index.ts +++ b/packages/jest-snapshot/src/index.ts @@ -47,7 +47,8 @@ const NOT_SNAPSHOT_MATCHERS = `.${BOLD_WEIGHT( 'not', )} cannot be used with snapshot matchers`; -const HINT_ARG = BOLD_WEIGHT('hint'); +const HINT_ARG = 'hint'; +const HINT_COLOR = BOLD_WEIGHT; const INLINE_SNAPSHOT_ARG = 'snapshot'; const PROPERTY_MATCHERS_ARG = 'properties'; const INDENTATION_REGEX = /^([^\S\n]*)\S/m; @@ -186,6 +187,13 @@ const toMatchSnapshot = function( secondArgument, }; + if (expectedArgument === HINT_ARG) { + options.expectedColor = HINT_COLOR; + } + if (secondArgument === HINT_ARG) { + options.secondArgumentColor = HINT_COLOR; + } + if (arguments.length === 3 && !propertyMatchers) { throw new Error( 'Property matchers must be an object.\n\nTo provide a snapshot test name without property matchers, use: toMatchSnapshot("name")', @@ -385,6 +393,7 @@ const toThrowErrorMatchingSnapshot = function( const expectedArgument = typeof hint === 'string' && hint.length !== 0 ? HINT_ARG : ''; const options = { + expectedColor: HINT_COLOR, isNot: this.isNot, promise: this.promise, secondArgument: '',