From 71eb4066b93ae335f19cef7e8fdbf70f0c8c349b Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Mon, 22 Oct 2018 16:26:19 -0400 Subject: [PATCH 01/10] expect: Improve report when assertion fails, part 4 --- .../__snapshots__/matchers.test.js.snap | 379 ++++++++------- .../__snapshots__/spy_matchers.test.js.snap | 456 +++++++++--------- .../to_throw_matchers.test.js.snap | 30 +- .../src/__tests__/assertion_counts.test.js | 2 +- packages/expect/src/index.js | 18 +- packages/expect/src/matchers.js | 133 +++-- packages/expect/src/spy_matchers.js | 9 +- packages/expect/src/to_throw_matchers.js | 23 +- .../src/__tests__/index.test.js | 8 +- packages/jest-matcher-utils/src/index.js | 48 +- 10 files changed, 581 insertions(+), 525 deletions(-) diff --git a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap index 400e8b6e424d..e3ebe236c4bd 100644 --- a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap @@ -10,62 +10,64 @@ Expected received Promise to reject, instead it resolved to value exports[`.rejects fails non-promise value "a" 1`] = ` "expect(received).rejects.toBeDefined() -received value must be a Promise. -Received: - string: \\"a\\"" +Matcher error: Received value must be Promise + +Received string: \\"a\\"" `; exports[`.rejects fails non-promise value [1] 1`] = ` "expect(received).rejects.toBeDefined() -received value must be a Promise. -Received: - array: [1]" +Matcher error: Received value must be Promise + +Received array: [1]" `; exports[`.rejects fails non-promise value [Function anonymous] 1`] = ` "expect(received).rejects.toBeDefined() -received value must be a Promise. -Received: - function: [Function anonymous]" +Matcher error: Received value must be Promise + +Received function: [Function anonymous]" `; exports[`.rejects fails non-promise value {"a": 1} 1`] = ` "expect(received).rejects.toBeDefined() -received value must be a Promise. -Received: - object: {\\"a\\": 1}" +Matcher error: Received value must be Promise + +Received object: {\\"a\\": 1}" `; exports[`.rejects fails non-promise value 4 1`] = ` "expect(received).rejects.toBeDefined() -received value must be a Promise. -Received: - number: 4" +Matcher error: Received value must be Promise + +Received number: 4" `; exports[`.rejects fails non-promise value null 1`] = ` "expect(received).rejects.toBeDefined() -received value must be a Promise. +Matcher error: Received value must be Promise + Received: null" `; exports[`.rejects fails non-promise value true 1`] = ` "expect(received).rejects.toBeDefined() -received value must be a Promise. -Received: - boolean: true" +Matcher error: Received value must be Promise + +Received boolean: true" `; exports[`.rejects fails non-promise value undefined 1`] = ` "expect(received).rejects.toBeDefined() -received value must be a Promise. +Matcher error: Received value must be Promise + Received: undefined" `; @@ -79,124 +81,128 @@ Expected received Promise to resolve, instead it rejected to value exports[`.resolves fails non-promise value "a" 1`] = ` "expect(received).resolves.toBeDefined() -received value must be a Promise. -Received: - string: \\"a\\"" +Matcher error: Received value must be Promise + +Received string: \\"a\\"" `; exports[`.resolves fails non-promise value "a" synchronously 1`] = ` "expect(received).resolves.toBeDefined() -received value must be a Promise. -Received: - string: \\"a\\"" +Matcher error: Received value must be Promise + +Received string: \\"a\\"" `; exports[`.resolves fails non-promise value [1] 1`] = ` "expect(received).resolves.toBeDefined() -received value must be a Promise. -Received: - array: [1]" +Matcher error: Received value must be Promise + +Received array: [1]" `; exports[`.resolves fails non-promise value [1] synchronously 1`] = ` "expect(received).resolves.toBeDefined() -received value must be a Promise. -Received: - array: [1]" +Matcher error: Received value must be Promise + +Received array: [1]" `; exports[`.resolves fails non-promise value [Function anonymous] 1`] = ` "expect(received).resolves.toBeDefined() -received value must be a Promise. -Received: - function: [Function anonymous]" +Matcher error: Received value must be Promise + +Received function: [Function anonymous]" `; exports[`.resolves fails non-promise value [Function anonymous] synchronously 1`] = ` "expect(received).resolves.toBeDefined() -received value must be a Promise. -Received: - function: [Function anonymous]" +Matcher error: Received value must be Promise + +Received function: [Function anonymous]" `; exports[`.resolves fails non-promise value {"a": 1} 1`] = ` "expect(received).resolves.toBeDefined() -received value must be a Promise. -Received: - object: {\\"a\\": 1}" +Matcher error: Received value must be Promise + +Received object: {\\"a\\": 1}" `; exports[`.resolves fails non-promise value {"a": 1} synchronously 1`] = ` "expect(received).resolves.toBeDefined() -received value must be a Promise. -Received: - object: {\\"a\\": 1}" +Matcher error: Received value must be Promise + +Received object: {\\"a\\": 1}" `; exports[`.resolves fails non-promise value 4 1`] = ` "expect(received).resolves.toBeDefined() -received value must be a Promise. -Received: - number: 4" +Matcher error: Received value must be Promise + +Received number: 4" `; exports[`.resolves fails non-promise value 4 synchronously 1`] = ` "expect(received).resolves.toBeDefined() -received value must be a Promise. -Received: - number: 4" +Matcher error: Received value must be Promise + +Received number: 4" `; exports[`.resolves fails non-promise value null 1`] = ` "expect(received).resolves.toBeDefined() -received value must be a Promise. +Matcher error: Received value must be Promise + Received: null" `; exports[`.resolves fails non-promise value null synchronously 1`] = ` "expect(received).resolves.toBeDefined() -received value must be a Promise. +Matcher error: Received value must be Promise + Received: null" `; exports[`.resolves fails non-promise value true 1`] = ` "expect(received).resolves.toBeDefined() -received value must be a Promise. -Received: - boolean: true" +Matcher error: Received value must be Promise + +Received boolean: true" `; exports[`.resolves fails non-promise value true synchronously 1`] = ` "expect(received).resolves.toBeDefined() -received value must be a Promise. -Received: - boolean: true" +Matcher error: Received value must be Promise + +Received boolean: true" `; exports[`.resolves fails non-promise value undefined 1`] = ` "expect(received).resolves.toBeDefined() -received value must be a Promise. +Matcher error: Received value must be Promise + Received: undefined" `; exports[`.resolves fails non-promise value undefined synchronously 1`] = ` "expect(received).resolves.toBeDefined() -received value must be a Promise. +Matcher error: Received value must be Promise + Received: undefined" `; @@ -1124,10 +1130,11 @@ Received value: Map {}" `; exports[`.toBeInstanceOf() throws if constructor is not a function 1`] = ` -"expect(value).toBeInstanceOf(constructor) +"expect(received).toBeInstanceOf(expected) -Expected constructor to be a function. Instead got: - \\"number\\"" +Matcher error: Expected value must be function + +Expected number: 4" `; exports[`.toBeNaN() {pass: true} expect(NaN).toBeNaN() 1`] = ` @@ -1457,15 +1464,17 @@ Received: undefined" exports[`.toBeTruthy(), .toBeFalsy() does not accept arguments 1`] = ` "expect(received)[.not].toBeTruthy() -Matcher does not accept any arguments. -Got: null" +Matcher error: Expected value must be omitted or undefined + +Expected: null" `; exports[`.toBeTruthy(), .toBeFalsy() does not accept arguments 2`] = ` "expect(received)[.not].toBeFalsy() -Matcher does not accept any arguments. -Got: null" +Matcher error: Expected value must be omitted or undefined + +Expected: null" `; exports[`.toContain(), .toContainEqual() '"11112111"' contains '"2"' 1`] = ` @@ -1688,16 +1697,18 @@ Not to contain a value equal to: `; exports[`.toContain(), .toContainEqual() error cases 1`] = ` -"expect(collection)[.not].toContainEqual(value) +"expect(received).toContain(expected) + +Matcher error: Received value cannot be null or undefined -Expected collection to be an array-like structure. Received: null" `; exports[`.toContain(), .toContainEqual() error cases for toContainEqual 1`] = ` -"expect(collection)[.not].toContainEqual(value) +"expect(received).toContainEqual(expected) + +Matcher error: Received value cannot be null or undefined -Expected collection to be an array-like structure. Received: null" `; @@ -2850,63 +2861,67 @@ received.length: `; exports[`.toHaveLength error cases 1`] = ` -"expect(received)[.not].toHaveLength(length) +"expect(received).toHaveLength(expected) -Expected value to have a 'length' property that is a number. Received: - {\\"a\\": 9} -received.length: - undefined" +Matcher error: Received value must have length property whose value must be number + +Received object: {\\"a\\": 9}" `; exports[`.toHaveLength error cases 2`] = ` -"expect(received)[.not].toHaveLength(length) +"expect(received).toHaveLength(expected) -Expected value to have a 'length' property that is a number. Received: - 0 -" +Matcher error: Received value must have length property whose value must be number + +Received number: 0" `; exports[`.toHaveLength error cases 3`] = ` -"expect(received)[.not].toHaveLength(length) +"expect(received).toHaveLength(expected) -Expected value to have a 'length' property that is a number. Received: - undefined -" +Matcher error: Received value must have length property whose value must be number + +Received: undefined" `; exports[`.toHaveProperty() {error} expect({"a": {"b": {}}}).toHaveProperty('1') 1`] = ` -"expect(object)[.not].toHaveProperty(path) +"expect(received).toHaveProperty(path) + +Matcher error: Expected path must be string or array -Expected path to be a string or an array. Received: - number: 1" +Expected number: 1" `; exports[`.toHaveProperty() {error} expect({"a": {"b": {}}}).toHaveProperty('null') 1`] = ` -"expect(object)[.not].toHaveProperty(path) +"expect(received).toHaveProperty(path) + +Matcher error: Expected path must be string or array -Expected path to be a string or an array. Received: - null: null" +Expected: null" `; exports[`.toHaveProperty() {error} expect({"a": {"b": {}}}).toHaveProperty('undefined') 1`] = ` -"expect(object)[.not].toHaveProperty(path) +"expect(received).toHaveProperty(path) + +Matcher error: Expected path must be string or array -Expected path to be a string or an array. Received: - undefined: undefined" +Expected: undefined" `; exports[`.toHaveProperty() {error} expect(null).toHaveProperty('a.b') 1`] = ` -"expect(object)[.not].toHaveProperty(path) +"expect(received).toHaveProperty(path) + +Matcher error: Received value cannot be null or undefined -Expected object to be an object. Received: - null: null" +Received: null" `; exports[`.toHaveProperty() {error} expect(undefined).toHaveProperty('a') 1`] = ` -"expect(object)[.not].toHaveProperty(path) +"expect(received).toHaveProperty(path) + +Matcher error: Received value cannot be null or undefined -Expected object to be an object. Received: - undefined: undefined" +Received: undefined" `; exports[`.toHaveProperty() {pass: false} expect("abc").toHaveProperty('a.b.c') 1`] = ` @@ -3360,104 +3375,106 @@ Received: `; exports[`.toMatch() throws if non String actual value passed: [/foo/i, "foo"] 1`] = ` -"expect(string)[.not].toMatch(expected) +"expect(received).toMatch(expected) -string value must be a string. -Received: - regexp: /foo/i" +Matcher error: Received value must be string + +Received regexp: /foo/i" `; exports[`.toMatch() throws if non String actual value passed: [[], "foo"] 1`] = ` -"expect(string)[.not].toMatch(expected) +"expect(received).toMatch(expected) -string value must be a string. -Received: - array: []" +Matcher error: Received value must be string + +Received array: []" `; exports[`.toMatch() throws if non String actual value passed: [[Function anonymous], "foo"] 1`] = ` -"expect(string)[.not].toMatch(expected) +"expect(received).toMatch(expected) -string value must be a string. -Received: - function: [Function anonymous]" +Matcher error: Received value must be string + +Received function: [Function anonymous]" `; exports[`.toMatch() throws if non String actual value passed: [{}, "foo"] 1`] = ` -"expect(string)[.not].toMatch(expected) +"expect(received).toMatch(expected) -string value must be a string. -Received: - object: {}" +Matcher error: Received value must be string + +Received object: {}" `; exports[`.toMatch() throws if non String actual value passed: [1, "foo"] 1`] = ` -"expect(string)[.not].toMatch(expected) +"expect(received).toMatch(expected) -string value must be a string. -Received: - number: 1" +Matcher error: Received value must be string + +Received number: 1" `; exports[`.toMatch() throws if non String actual value passed: [true, "foo"] 1`] = ` -"expect(string)[.not].toMatch(expected) +"expect(received).toMatch(expected) -string value must be a string. -Received: - boolean: true" +Matcher error: Received value must be string + +Received boolean: true" `; exports[`.toMatch() throws if non String actual value passed: [undefined, "foo"] 1`] = ` -"expect(string)[.not].toMatch(expected) +"expect(received).toMatch(expected) + +Matcher error: Received value must be string -string value must be a string. Received: undefined" `; exports[`.toMatch() throws if non String/RegExp expected value passed: ["foo", []] 1`] = ` -"expect(string)[.not].toMatch(expected) +"expect(received).toMatch(expected) -expected value must be a string or a regular expression. -Expected: - array: []" +Matcher error: Expected value must be string or regular expression + +Expected array: []" `; exports[`.toMatch() throws if non String/RegExp expected value passed: ["foo", [Function anonymous]] 1`] = ` -"expect(string)[.not].toMatch(expected) +"expect(received).toMatch(expected) + +Matcher error: Expected value must be string or regular expression -expected value must be a string or a regular expression. -Expected: - function: [Function anonymous]" +Expected function: [Function anonymous]" `; exports[`.toMatch() throws if non String/RegExp expected value passed: ["foo", {}] 1`] = ` -"expect(string)[.not].toMatch(expected) +"expect(received).toMatch(expected) + +Matcher error: Expected value must be string or regular expression -expected value must be a string or a regular expression. -Expected: - object: {}" +Expected object: {}" `; exports[`.toMatch() throws if non String/RegExp expected value passed: ["foo", 1] 1`] = ` -"expect(string)[.not].toMatch(expected) +"expect(received).toMatch(expected) + +Matcher error: Expected value must be string or regular expression -expected value must be a string or a regular expression. -Expected: - number: 1" +Expected number: 1" `; exports[`.toMatch() throws if non String/RegExp expected value passed: ["foo", true] 1`] = ` -"expect(string)[.not].toMatch(expected) +"expect(received).toMatch(expected) + +Matcher error: Expected value must be string or regular expression -expected value must be a string or a regular expression. -Expected: - boolean: true" +Expected boolean: true" `; exports[`.toMatch() throws if non String/RegExp expected value passed: ["foo", undefined] 1`] = ` -"expect(string)[.not].toMatch(expected) +"expect(received).toMatch(expected) + +Matcher error: Expected value must be string or regular expression -expected value must be a string or a regular expression. Expected: undefined" `; @@ -4120,77 +4137,81 @@ Received: `; exports[`toMatchObject() throws expect("44").toMatchObject({}) 1`] = ` -"expect(object)[.not].toMatchObject(expected) +"expect(received).toMatchObject(expected) -received value must be an object. -Received: - string: \\"44\\"" +Matcher error: Received value must be non-null object + +Received string: \\"44\\"" `; exports[`toMatchObject() throws expect({}).toMatchObject("some string") 1`] = ` -"expect(object)[.not].toMatchObject(expected) +"expect(received).toMatchObject(expected) -expected value must be an object. -Expected: - string: \\"some string\\"" +Matcher error: Expected value must be non-null object + +Expected string: \\"some string\\"" `; exports[`toMatchObject() throws expect({}).toMatchObject(4) 1`] = ` -"expect(object)[.not].toMatchObject(expected) +"expect(received).toMatchObject(expected) -expected value must be an object. -Expected: - number: 4" +Matcher error: Expected value must be non-null object + +Expected number: 4" `; exports[`toMatchObject() throws expect({}).toMatchObject(null) 1`] = ` -"expect(object)[.not].toMatchObject(expected) +"expect(received).toMatchObject(expected) + +Matcher error: Expected value must be non-null object -expected value must be an object. Expected: null" `; exports[`toMatchObject() throws expect({}).toMatchObject(true) 1`] = ` -"expect(object)[.not].toMatchObject(expected) +"expect(received).toMatchObject(expected) -expected value must be an object. -Expected: - boolean: true" +Matcher error: Expected value must be non-null object + +Expected boolean: true" `; exports[`toMatchObject() throws expect({}).toMatchObject(undefined) 1`] = ` -"expect(object)[.not].toMatchObject(expected) +"expect(received).toMatchObject(expected) + +Matcher error: Expected value must be non-null object -expected value must be an object. Expected: undefined" `; exports[`toMatchObject() throws expect(4).toMatchObject({}) 1`] = ` -"expect(object)[.not].toMatchObject(expected) +"expect(received).toMatchObject(expected) -received value must be an object. -Received: - number: 4" +Matcher error: Received value must be non-null object + +Received number: 4" `; exports[`toMatchObject() throws expect(null).toMatchObject({}) 1`] = ` -"expect(object)[.not].toMatchObject(expected) +"expect(received).toMatchObject(expected) + +Matcher error: Received value must be non-null object -received value must be an object. Received: null" `; exports[`toMatchObject() throws expect(true).toMatchObject({}) 1`] = ` -"expect(object)[.not].toMatchObject(expected) +"expect(received).toMatchObject(expected) -received value must be an object. -Received: - boolean: true" +Matcher error: Received value must be non-null object + +Received boolean: true" `; exports[`toMatchObject() throws expect(undefined).toMatchObject({}) 1`] = ` -"expect(object)[.not].toMatchObject(expected) +"expect(received).toMatchObject(expected) + +Matcher error: Received value must be non-null object -received value must be an object. Received: undefined" `; diff --git a/packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap index 95a15e70ccf4..dd6997f92b8a 100644 --- a/packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap @@ -10,9 +10,9 @@ Expected mock function \\"named-mock\\" to not have been last called with: exports[`lastCalledWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].lastCalledWith() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`lastCalledWith works when not called 1`] = ` @@ -152,9 +152,9 @@ But it was not called" exports[`lastReturnedWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].lastReturnedWith() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`lastReturnedWith works when not called 1`] = ` @@ -276,9 +276,9 @@ Expected mock function first call to not have been called with: exports[`nthCalledWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].nthCalledWith() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`nthCalledWith works when not called 1`] = ` @@ -439,9 +439,9 @@ But the first call returned exactly: exports[`nthReturnedWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].nthReturnedWith() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`nthReturnedWith works when not called 1`] = ` @@ -545,9 +545,9 @@ But the first call returned exactly: exports[`toBeCalled .not fails with any argument passed 1`] = ` "expect(received)[.not].toBeCalled() -Matcher does not accept any arguments. -Got: - number: 555" +Matcher error: Expected value must be omitted or undefined + +Expected number: 555" `; exports[`toBeCalled .not passes when called 1`] = ` @@ -559,9 +559,9 @@ Expected mock function to have been called, but it was not called." exports[`toBeCalled fails with any argument passed 1`] = ` "expect(received)[.not].toBeCalled() -Matcher does not accept any arguments. -Got: - number: 555" +Matcher error: Expected value must be omitted or undefined + +Expected number: 555" `; exports[`toBeCalled includes the custom mock name in the error message 1`] = ` @@ -581,57 +581,57 @@ Expected mock function not to be called but it was called with: exports[`toBeCalled works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toBeCalled() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`toBeCalledTimes .not only accepts a number argument 1`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Expected value must be a number. -Got: - object: {}" +Matcher error: Expected value must be number + +Expected object: {}" `; exports[`toBeCalledTimes .not only accepts a number argument 2`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Expected value must be a number. -Got: - array: []" +Matcher error: Expected value must be number + +Expected array: []" `; exports[`toBeCalledTimes .not only accepts a number argument 3`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Expected value must be a number. -Got: - boolean: true" +Matcher error: Expected value must be number + +Expected boolean: true" `; exports[`toBeCalledTimes .not only accepts a number argument 4`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Expected value must be a number. -Got: - string: \\"a\\"" +Matcher error: Expected value must be number + +Expected string: \\"a\\"" `; exports[`toBeCalledTimes .not only accepts a number argument 5`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Expected value must be a number. -Got: - map: Map {}" +Matcher error: Expected value must be number + +Expected map: Map {}" `; exports[`toBeCalledTimes .not only accepts a number argument 6`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Expected value must be a number. -Got: - function: [Function anonymous]" +Matcher error: Expected value must be number + +Expected function: [Function anonymous]" `; exports[`toBeCalledTimes .not passes if function called less than expected times 1`] = ` @@ -655,49 +655,49 @@ Expected mock function \\"named-mock\\" to have been called two times, exports[`toBeCalledTimes only accepts a number argument 1`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Expected value must be a number. -Got: - object: {}" +Matcher error: Expected value must be number + +Expected object: {}" `; exports[`toBeCalledTimes only accepts a number argument 2`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Expected value must be a number. -Got: - array: []" +Matcher error: Expected value must be number + +Expected array: []" `; exports[`toBeCalledTimes only accepts a number argument 3`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Expected value must be a number. -Got: - boolean: true" +Matcher error: Expected value must be number + +Expected boolean: true" `; exports[`toBeCalledTimes only accepts a number argument 4`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Expected value must be a number. -Got: - string: \\"a\\"" +Matcher error: Expected value must be number + +Expected string: \\"a\\"" `; exports[`toBeCalledTimes only accepts a number argument 5`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Expected value must be a number. -Got: - map: Map {}" +Matcher error: Expected value must be number + +Expected map: Map {}" `; exports[`toBeCalledTimes only accepts a number argument 6`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Expected value must be a number. -Got: - function: [Function anonymous]" +Matcher error: Expected value must be number + +Expected function: [Function anonymous]" `; exports[`toBeCalledTimes passes if function called equal to expected times 1`] = ` @@ -709,9 +709,9 @@ Expected mock function not to be called two times, but it was called e exports[`toBeCalledTimes works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toBeCalledTimes() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`toBeCalledWith includes the custom mock name in the error message 1`] = ` @@ -724,9 +724,9 @@ Expected mock function \\"named-mock\\" not to have been called with: exports[`toBeCalledWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toBeCalledWith() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`toBeCalledWith works when not called 1`] = ` @@ -850,9 +850,9 @@ Expected mock function to have been called with: exports[`toHaveBeenCalled .not fails with any argument passed 1`] = ` "expect(received)[.not].toHaveBeenCalled() -Matcher does not accept any arguments. -Got: - number: 555" +Matcher error: Expected value must be omitted or undefined + +Expected number: 555" `; exports[`toHaveBeenCalled .not passes when called 1`] = ` @@ -864,9 +864,9 @@ Expected mock function to have been called, but it was not called." exports[`toHaveBeenCalled fails with any argument passed 1`] = ` "expect(received)[.not].toHaveBeenCalled() -Matcher does not accept any arguments. -Got: - number: 555" +Matcher error: Expected value must be omitted or undefined + +Expected number: 555" `; exports[`toHaveBeenCalled includes the custom mock name in the error message 1`] = ` @@ -886,57 +886,57 @@ Expected mock function not to be called but it was called with: exports[`toHaveBeenCalled works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveBeenCalled() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`toHaveBeenCalledTimes .not only accepts a number argument 1`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Expected value must be a number. -Got: - object: {}" +Matcher error: Expected value must be number + +Expected object: {}" `; exports[`toHaveBeenCalledTimes .not only accepts a number argument 2`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Expected value must be a number. -Got: - array: []" +Matcher error: Expected value must be number + +Expected array: []" `; exports[`toHaveBeenCalledTimes .not only accepts a number argument 3`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Expected value must be a number. -Got: - boolean: true" +Matcher error: Expected value must be number + +Expected boolean: true" `; exports[`toHaveBeenCalledTimes .not only accepts a number argument 4`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Expected value must be a number. -Got: - string: \\"a\\"" +Matcher error: Expected value must be number + +Expected string: \\"a\\"" `; exports[`toHaveBeenCalledTimes .not only accepts a number argument 5`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Expected value must be a number. -Got: - map: Map {}" +Matcher error: Expected value must be number + +Expected map: Map {}" `; exports[`toHaveBeenCalledTimes .not only accepts a number argument 6`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Expected value must be a number. -Got: - function: [Function anonymous]" +Matcher error: Expected value must be number + +Expected function: [Function anonymous]" `; exports[`toHaveBeenCalledTimes .not passes if function called less than expected times 1`] = ` @@ -960,49 +960,49 @@ Expected mock function \\"named-mock\\" to have been called two times, exports[`toHaveBeenCalledTimes only accepts a number argument 1`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Expected value must be a number. -Got: - object: {}" +Matcher error: Expected value must be number + +Expected object: {}" `; exports[`toHaveBeenCalledTimes only accepts a number argument 2`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Expected value must be a number. -Got: - array: []" +Matcher error: Expected value must be number + +Expected array: []" `; exports[`toHaveBeenCalledTimes only accepts a number argument 3`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Expected value must be a number. -Got: - boolean: true" +Matcher error: Expected value must be number + +Expected boolean: true" `; exports[`toHaveBeenCalledTimes only accepts a number argument 4`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Expected value must be a number. -Got: - string: \\"a\\"" +Matcher error: Expected value must be number + +Expected string: \\"a\\"" `; exports[`toHaveBeenCalledTimes only accepts a number argument 5`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Expected value must be a number. -Got: - map: Map {}" +Matcher error: Expected value must be number + +Expected map: Map {}" `; exports[`toHaveBeenCalledTimes only accepts a number argument 6`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Expected value must be a number. -Got: - function: [Function anonymous]" +Matcher error: Expected value must be number + +Expected function: [Function anonymous]" `; exports[`toHaveBeenCalledTimes passes if function called equal to expected times 1`] = ` @@ -1014,9 +1014,9 @@ Expected mock function not to be called two times, but it was called e exports[`toHaveBeenCalledTimes works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveBeenCalledTimes() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`toHaveBeenCalledWith includes the custom mock name in the error message 1`] = ` @@ -1029,9 +1029,9 @@ Expected mock function \\"named-mock\\" not to have been called with: exports[`toHaveBeenCalledWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveBeenCalledWith() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`toHaveBeenCalledWith works when not called 1`] = ` @@ -1162,9 +1162,9 @@ Expected mock function \\"named-mock\\" to not have been last called with: exports[`toHaveBeenLastCalledWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveBeenLastCalledWith() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`toHaveBeenLastCalledWith works when not called 1`] = ` @@ -1307,9 +1307,9 @@ Expected mock function first call to not have been called with: exports[`toHaveBeenNthCalledWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveBeenNthCalledWith() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`toHaveBeenNthCalledWith works when not called 1`] = ` @@ -1440,9 +1440,9 @@ But it was not called" exports[`toHaveLastReturnedWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveLastReturnedWith() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`toHaveLastReturnedWith works when not called 1`] = ` @@ -1591,9 +1591,9 @@ But the first call returned exactly: exports[`toHaveNthReturnedWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveNthReturnedWith() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`toHaveNthReturnedWith works when not called 1`] = ` @@ -1697,9 +1697,9 @@ But the first call returned exactly: exports[`toHaveReturned .not fails with any argument passed 1`] = ` "expect(received)[.not].toHaveReturned() -Matcher does not accept any arguments. -Got: - number: 555" +Matcher error: Expected value must be omitted or undefined + +Expected number: 555" `; exports[`toHaveReturned .not passes when a call throws undefined 1`] = ` @@ -1723,9 +1723,9 @@ Expected mock function to have returned." exports[`toHaveReturned fails with any argument passed 1`] = ` "expect(received)[.not].toHaveReturned() -Matcher does not accept any arguments. -Got: - number: 555" +Matcher error: Expected value must be omitted or undefined + +Expected number: 555" `; exports[`toHaveReturned includes the custom mock name in the error message 1`] = ` @@ -1761,57 +1761,57 @@ Expected mock function not to have returned, but it returned: exports[`toHaveReturned works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveReturned() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`toHaveReturnedTimes .not only accepts a number argument 1`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Expected value must be a number. -Got: - object: {}" +Matcher error: Expected value must be number + +Expected object: {}" `; exports[`toHaveReturnedTimes .not only accepts a number argument 2`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Expected value must be a number. -Got: - array: []" +Matcher error: Expected value must be number + +Expected array: []" `; exports[`toHaveReturnedTimes .not only accepts a number argument 3`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Expected value must be a number. -Got: - boolean: true" +Matcher error: Expected value must be number + +Expected boolean: true" `; exports[`toHaveReturnedTimes .not only accepts a number argument 4`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Expected value must be a number. -Got: - string: \\"a\\"" +Matcher error: Expected value must be number + +Expected string: \\"a\\"" `; exports[`toHaveReturnedTimes .not only accepts a number argument 5`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Expected value must be a number. -Got: - map: Map {}" +Matcher error: Expected value must be number + +Expected map: Map {}" `; exports[`toHaveReturnedTimes .not only accepts a number argument 6`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Expected value must be a number. -Got: - function: [Function anonymous]" +Matcher error: Expected value must be number + +Expected function: [Function anonymous]" `; exports[`toHaveReturnedTimes .not passes if function called less than expected times 1`] = ` @@ -1853,49 +1853,49 @@ Expected mock function \\"named-mock\\" to have returned one time, but exports[`toHaveReturnedTimes only accepts a number argument 1`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Expected value must be a number. -Got: - object: {}" +Matcher error: Expected value must be number + +Expected object: {}" `; exports[`toHaveReturnedTimes only accepts a number argument 2`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Expected value must be a number. -Got: - array: []" +Matcher error: Expected value must be number + +Expected array: []" `; exports[`toHaveReturnedTimes only accepts a number argument 3`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Expected value must be a number. -Got: - boolean: true" +Matcher error: Expected value must be number + +Expected boolean: true" `; exports[`toHaveReturnedTimes only accepts a number argument 4`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Expected value must be a number. -Got: - string: \\"a\\"" +Matcher error: Expected value must be number + +Expected string: \\"a\\"" `; exports[`toHaveReturnedTimes only accepts a number argument 5`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Expected value must be a number. -Got: - map: Map {}" +Matcher error: Expected value must be number + +Expected map: Map {}" `; exports[`toHaveReturnedTimes only accepts a number argument 6`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Expected value must be a number. -Got: - function: [Function anonymous]" +Matcher error: Expected value must be number + +Expected function: [Function anonymous]" `; exports[`toHaveReturnedTimes passes if function returned equal to expected times 1`] = ` @@ -1907,9 +1907,9 @@ Expected mock function not to have returned two times, but it returned exports[`toHaveReturnedTimes works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveReturnedTimes() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`toHaveReturnedWith a call that throws is not considered to have returned 1`] = ` @@ -1939,9 +1939,9 @@ But it did not return." exports[`toHaveReturnedWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveReturnedWith() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`toHaveReturnedWith works when not called 1`] = ` @@ -2055,9 +2055,9 @@ But it returned exactly: exports[`toReturn .not fails with any argument passed 1`] = ` "expect(received)[.not].toReturn() -Matcher does not accept any arguments. -Got: - number: 555" +Matcher error: Expected value must be omitted or undefined + +Expected number: 555" `; exports[`toReturn .not passes when a call throws undefined 1`] = ` @@ -2081,9 +2081,9 @@ Expected mock function to have returned." exports[`toReturn fails with any argument passed 1`] = ` "expect(received)[.not].toReturn() -Matcher does not accept any arguments. -Got: - number: 555" +Matcher error: Expected value must be omitted or undefined + +Expected number: 555" `; exports[`toReturn includes the custom mock name in the error message 1`] = ` @@ -2119,57 +2119,57 @@ Expected mock function not to have returned, but it returned: exports[`toReturn works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toReturn() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`toReturnTimes .not only accepts a number argument 1`] = ` "expect(received)[.not].toReturnTimes(expected) -Expected value must be a number. -Got: - object: {}" +Matcher error: Expected value must be number + +Expected object: {}" `; exports[`toReturnTimes .not only accepts a number argument 2`] = ` "expect(received)[.not].toReturnTimes(expected) -Expected value must be a number. -Got: - array: []" +Matcher error: Expected value must be number + +Expected array: []" `; exports[`toReturnTimes .not only accepts a number argument 3`] = ` "expect(received)[.not].toReturnTimes(expected) -Expected value must be a number. -Got: - boolean: true" +Matcher error: Expected value must be number + +Expected boolean: true" `; exports[`toReturnTimes .not only accepts a number argument 4`] = ` "expect(received)[.not].toReturnTimes(expected) -Expected value must be a number. -Got: - string: \\"a\\"" +Matcher error: Expected value must be number + +Expected string: \\"a\\"" `; exports[`toReturnTimes .not only accepts a number argument 5`] = ` "expect(received)[.not].toReturnTimes(expected) -Expected value must be a number. -Got: - map: Map {}" +Matcher error: Expected value must be number + +Expected map: Map {}" `; exports[`toReturnTimes .not only accepts a number argument 6`] = ` "expect(received)[.not].toReturnTimes(expected) -Expected value must be a number. -Got: - function: [Function anonymous]" +Matcher error: Expected value must be number + +Expected function: [Function anonymous]" `; exports[`toReturnTimes .not passes if function called less than expected times 1`] = ` @@ -2211,49 +2211,49 @@ Expected mock function \\"named-mock\\" to have returned one time, but exports[`toReturnTimes only accepts a number argument 1`] = ` "expect(received)[.not].toReturnTimes(expected) -Expected value must be a number. -Got: - object: {}" +Matcher error: Expected value must be number + +Expected object: {}" `; exports[`toReturnTimes only accepts a number argument 2`] = ` "expect(received)[.not].toReturnTimes(expected) -Expected value must be a number. -Got: - array: []" +Matcher error: Expected value must be number + +Expected array: []" `; exports[`toReturnTimes only accepts a number argument 3`] = ` "expect(received)[.not].toReturnTimes(expected) -Expected value must be a number. -Got: - boolean: true" +Matcher error: Expected value must be number + +Expected boolean: true" `; exports[`toReturnTimes only accepts a number argument 4`] = ` "expect(received)[.not].toReturnTimes(expected) -Expected value must be a number. -Got: - string: \\"a\\"" +Matcher error: Expected value must be number + +Expected string: \\"a\\"" `; exports[`toReturnTimes only accepts a number argument 5`] = ` "expect(received)[.not].toReturnTimes(expected) -Expected value must be a number. -Got: - map: Map {}" +Matcher error: Expected value must be number + +Expected map: Map {}" `; exports[`toReturnTimes only accepts a number argument 6`] = ` "expect(received)[.not].toReturnTimes(expected) -Expected value must be a number. -Got: - function: [Function anonymous]" +Matcher error: Expected value must be number + +Expected function: [Function anonymous]" `; exports[`toReturnTimes passes if function returned equal to expected times 1`] = ` @@ -2265,9 +2265,9 @@ Expected mock function not to have returned two times, but it returned exports[`toReturnTimes works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toReturnTimes() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`toReturnWith a call that throws is not considered to have returned 1`] = ` @@ -2297,9 +2297,9 @@ But it did not return." exports[`toReturnWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toReturnWith() -jest.fn() value must be a mock function or spy. -Received: - function: [Function fn]" +Matcher error: Received value must be mock or spy function + +Received function: [Function fn]" `; exports[`toReturnWith works when not called 1`] = ` diff --git a/packages/expect/src/__tests__/__snapshots__/to_throw_matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/to_throw_matchers.test.js.snap index af577d3e0811..5c44f7ccd91c 100644 --- a/packages/expect/src/__tests__/__snapshots__/to_throw_matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/to_throw_matchers.test.js.snap @@ -29,18 +29,19 @@ Instead, it threw: `; exports[`.toThrow() invalid actual 1`] = ` -"expect(function).toThrow(undefined) +"expect(received)[.not].toThrow(expected) -Received value must be a function, but instead \\"string\\" was found" +Matcher error: Received value must be function + +Received string: \\"a string\\"" `; exports[`.toThrow() invalid arguments 1`] = ` -"expect(function).not.toThrow(number) +"expect(received)[.not].toThrow(expected) + +Matcher error: Expected value must be string or regular expression or Error -Unexpected argument passed. -Expected: \\"string\\", \\"Error (type)\\" or \\"regexp\\". -Got: - string: \\"111\\"" +Expected number: 111" `; exports[`.toThrow() promise/async throws if Error-like object is returned did not throw at all 1`] = ` @@ -154,18 +155,19 @@ Instead, it threw: `; exports[`.toThrowError() invalid actual 1`] = ` -"expect(function).toThrowError(undefined) +"expect(received)[.not].toThrowError(expected) -Received value must be a function, but instead \\"string\\" was found" +Matcher error: Received value must be function + +Received string: \\"a string\\"" `; exports[`.toThrowError() invalid arguments 1`] = ` -"expect(function).not.toThrowError(number) +"expect(received)[.not].toThrowError(expected) + +Matcher error: Expected value must be string or regular expression or Error -Unexpected argument passed. -Expected: \\"string\\", \\"Error (type)\\" or \\"regexp\\". -Got: - string: \\"111\\"" +Expected number: 111" `; exports[`.toThrowError() promise/async throws if Error-like object is returned did not throw at all 1`] = ` diff --git a/packages/expect/src/__tests__/assertion_counts.test.js b/packages/expect/src/__tests__/assertion_counts.test.js index 6b59e8ae134d..f6b3bdab6adf 100644 --- a/packages/expect/src/__tests__/assertion_counts.test.js +++ b/packages/expect/src/__tests__/assertion_counts.test.js @@ -37,7 +37,7 @@ describe('.hasAssertions()', () => { it('throws if passed parameters', () => { jestExpect(() => { jestExpect.hasAssertions(2); - }).toThrow(/does not accept any arguments/); + }).toThrow(/Expected value must be omitted or undefined/); }); it('hasAssertions not leaking to global state', () => {}); diff --git a/packages/expect/src/index.js b/packages/expect/src/index.js index 573d1bf9b42c..8f048404328c 100644 --- a/packages/expect/src/index.js +++ b/packages/expect/src/index.js @@ -145,16 +145,15 @@ const makeResolveMatcher = ( const matcherStatement = `.resolves.${isNot ? 'not.' : ''}${matcherName}`; if (!isPromise(actual)) { throw new JestAssertionError( - matcherUtils.matcherHint(matcherStatement, 'received', '') + - '\n\n' + - `${matcherUtils.RECEIVED_COLOR( - 'received', - )} value must be a Promise.\n` + + matcherUtils.matcherErrorMessage( + matcherUtils.matcherHint(matcherStatement, undefined, ''), + 'Received value must be Promise', matcherUtils.printWithType( 'Received', actual, matcherUtils.printReceived, ), + ), ); } @@ -187,16 +186,15 @@ const makeRejectMatcher = ( const matcherStatement = `.rejects.${isNot ? 'not.' : ''}${matcherName}`; if (!isPromise(actual)) { throw new JestAssertionError( - matcherUtils.matcherHint(matcherStatement, 'received', '') + - '\n\n' + - `${matcherUtils.RECEIVED_COLOR( - 'received', - )} value must be a Promise.\n` + + matcherUtils.matcherErrorMessage( + matcherUtils.matcherHint(matcherStatement, undefined, ''), + 'Received value must be Promise', matcherUtils.printWithType( 'Received', actual, matcherUtils.printReceived, ), + ), ); } diff --git a/packages/expect/src/matchers.js b/packages/expect/src/matchers.js index 215114de52d5..a09efff741be 100644 --- a/packages/expect/src/matchers.js +++ b/packages/expect/src/matchers.js @@ -19,6 +19,7 @@ import { SUGGEST_TO_CONTAIN_EQUAL, ensureNoExpected, ensureNumbers, + matcherErrorMessage, matcherHint, printReceived, printExpected, @@ -156,12 +157,13 @@ const matchers: MatchersObject = { if (constType !== 'function') { throw new Error( - matcherHint('.toBeInstanceOf', 'value', 'constructor', { - isNot: this.isNot, - }) + - `\n\n` + - `Expected constructor to be a function. Instead got:\n` + - ` ${printExpected(constType)}`, + matcherErrorMessage( + matcherHint('.toBeInstanceOf', undefined, undefined, { + isNot: this.isNot, + }), + 'Expected value must be function', + printWithType('Expected', constructor, printExpected), + ), ); } const pass = received instanceof constructor; @@ -282,12 +284,13 @@ const matchers: MatchersObject = { converted = Array.from(collection); } catch (e) { throw new Error( - matcherHint('[.not].toContainEqual', 'collection', 'value') + - '\n\n' + - `Expected ${RECEIVED_COLOR( - 'collection', - )} to be an array-like structure.\n` + + matcherErrorMessage( + matcherHint('.toContain', undefined, undefined, { + isNot: this.isNot, + }), + 'Received value cannot be null or undefined', printWithType('Received', collection, printReceived), + ), ); } } @@ -334,12 +337,13 @@ const matchers: MatchersObject = { converted = Array.from(collection); } catch (e) { throw new Error( - matcherHint('[.not].toContainEqual', 'collection', 'value') + - '\n\n' + - `Expected ${RECEIVED_COLOR( - 'collection', - )} to be an array-like structure.\n` + + matcherErrorMessage( + matcherHint('.toContainEqual', undefined, undefined, { + isNot: this.isNot, + }), + 'Received value cannot be null or undefined', printWithType('Received', collection, printReceived), + ), ); } } @@ -404,14 +408,25 @@ const matchers: MatchersObject = { (!received || typeof received.length !== 'number') ) { throw new Error( - matcherHint('[.not].toHaveLength', 'received', 'length') + - '\n\n' + - `Expected value to have a 'length' property that is a number. ` + - `Received:\n` + - ` ${printReceived(received)}\n` + - (received - ? `received.length:\n ${printReceived(received.length)}` - : ''), + matcherErrorMessage( + matcherHint('.toHaveLength', undefined, undefined, { + isNot: this.isNot, + }), + 'Received value must have length property whose value must be number', + printWithType('Received', received, printReceived), + ), + ); + } + + if (typeof length !== 'number') { + throw new Error( + matcherErrorMessage( + matcherHint('.toHaveLength', undefined, undefined, { + isNot: this.isNot, + }), + 'Expected value must be number', + printWithType('Expected', length, printExpected), + ), ); } @@ -443,14 +458,16 @@ const matchers: MatchersObject = { const valuePassed = arguments.length === 3; const secondArgument = valuePassed ? 'value' : null; - if (!object && typeof object !== 'string' && typeof object !== 'number') { + if (object === null || object === undefined) { throw new Error( - matcherHint('[.not].toHaveProperty', 'object', 'path', { - secondArgument, - }) + - '\n\n' + - `Expected ${RECEIVED_COLOR('object')} to be an object. Received:\n` + - ` ${getType(object)}: ${printReceived(object)}`, + matcherErrorMessage( + matcherHint('.toHaveProperty', undefined, 'path', { + isNot: this.isNot, + secondArgument, + }), + 'Received value cannot be null or undefined', + printWithType('Received', object, printReceived), + ), ); } @@ -458,14 +475,14 @@ const matchers: MatchersObject = { if (keyPathType !== 'string' && keyPathType !== 'array') { throw new Error( - matcherHint('[.not].toHaveProperty', 'object', 'path', { - secondArgument, - }) + - '\n\n' + - `Expected ${EXPECTED_COLOR( - 'path', - )} to be a string or an array. Received:\n` + - ` ${keyPathType}: ${printReceived(keyPath)}`, + matcherErrorMessage( + matcherHint('.toHaveProperty', undefined, 'path', { + isNot: this.isNot, + secondArgument, + }), + 'Expected path must be string or array', + printWithType('Expected', keyPath, printExpected), + ), ); } @@ -527,10 +544,13 @@ const matchers: MatchersObject = { toMatch(received: string, expected: string | RegExp) { if (typeof received !== 'string') { throw new Error( - matcherHint('[.not].toMatch', 'string', 'expected') + - '\n\n' + - `${RECEIVED_COLOR('string')} value must be a string.\n` + + matcherErrorMessage( + matcherHint('.toMatch', undefined, undefined, { + isNot: this.isNot, + }), + 'Received value must be string', printWithType('Received', received, printReceived), + ), ); } @@ -539,12 +559,13 @@ const matchers: MatchersObject = { !(typeof expected === 'string') ) { throw new Error( - matcherHint('[.not].toMatch', 'string', 'expected') + - '\n\n' + - `${EXPECTED_COLOR( - 'expected', - )} value must be a string or a regular expression.\n` + + matcherErrorMessage( + matcherHint('.toMatch', undefined, undefined, { + isNot: this.isNot, + }), + 'Expected value must be string or regular expression', printWithType('Expected', expected, printExpected), + ), ); } @@ -571,19 +592,25 @@ const matchers: MatchersObject = { toMatchObject(receivedObject: Object, expectedObject: Object) { if (typeof receivedObject !== 'object' || receivedObject === null) { throw new Error( - matcherHint('[.not].toMatchObject', 'object', 'expected') + - '\n\n' + - `${RECEIVED_COLOR('received')} value must be an object.\n` + + matcherErrorMessage( + matcherHint('.toMatchObject', undefined, undefined, { + isNot: this.isNot, + }), + 'Received value must be non-null object', printWithType('Received', receivedObject, printReceived), + ), ); } if (typeof expectedObject !== 'object' || expectedObject === null) { throw new Error( - matcherHint('[.not].toMatchObject', 'object', 'expected') + - '\n\n' + - `${EXPECTED_COLOR('expected')} value must be an object.\n` + + matcherErrorMessage( + matcherHint('.toMatchObject', undefined, undefined, { + isNot: this.isNot, + }), + 'Expected value must be non-null object', printWithType('Expected', expectedObject, printExpected), + ), ); } diff --git a/packages/expect/src/spy_matchers.js b/packages/expect/src/spy_matchers.js index 2a176fb9e1f1..7f38c3d9f1f1 100644 --- a/packages/expect/src/spy_matchers.js +++ b/packages/expect/src/spy_matchers.js @@ -16,6 +16,7 @@ import { ensureExpectedIsNumber, ensureNoExpected, EXPECTED_COLOR, + matcherErrorMessage, matcherHint, pluralize, printExpected, @@ -465,11 +466,11 @@ const ensureMock = (mockOrSpy, matcherName) => { mockOrSpy._isMockFunction !== true) ) { throw new Error( - matcherHint('[.not]' + matcherName, 'jest.fn()', '') + - '\n\n' + - `${RECEIVED_COLOR('jest.fn()')} value must be a mock function ` + - `or spy.\n` + + matcherErrorMessage( + matcherHint('[.not]' + matcherName, 'jest.fn()', ''), + 'Received value must be mock or spy function', printWithType('Received', mockOrSpy, printReceived), + ), ); } }; diff --git a/packages/expect/src/to_throw_matchers.js b/packages/expect/src/to_throw_matchers.js index b5e953a10792..9b99356e23b8 100644 --- a/packages/expect/src/to_throw_matchers.js +++ b/packages/expect/src/to_throw_matchers.js @@ -15,8 +15,10 @@ import {formatStackTrace, separateMessageFromStack} from 'jest-message-util'; import { RECEIVED_COLOR, highlightTrailingWhitespace, + matcherErrorMessage, matcherHint, printExpected, + printReceived, printWithType, } from 'jest-matcher-utils'; import {equals} from './jasmine_utils'; @@ -35,10 +37,11 @@ export const createMatcher = (matcherName: string, fromPromise?: boolean) => ( if (typeof actual !== 'function') { if (!fromPromise) { throw new Error( - matcherHint(matcherName, 'function', getType(value)) + - '\n\n' + - 'Received value must be a function, but instead ' + - `"${getType(actual)}" was found`, + matcherErrorMessage( + matcherHint('[.not]' + matcherName, undefined, undefined), + 'Received value must be function', + printWithType('Received', actual, printReceived), + ), ); } } else { @@ -83,13 +86,11 @@ export const createMatcher = (matcherName: string, fromPromise?: boolean) => ( }; } else { throw new Error( - matcherHint('.not' + matcherName, 'function', getType(value)) + - '\n\n' + - 'Unexpected argument passed.\nExpected: ' + - `${printExpected('string')}, ${printExpected( - 'Error (type)', - )} or ${printExpected('regexp')}.\n` + - printWithType('Got', String(expected), printExpected), + matcherErrorMessage( + matcherHint('[.not]' + matcherName, undefined, undefined), + 'Expected value must be string or regular expression or Error', + printWithType('Expected', expected, printExpected), + ), ); } }; diff --git a/packages/jest-matcher-utils/src/__tests__/index.test.js b/packages/jest-matcher-utils/src/__tests__/index.test.js index 95cb4682ff09..7304185d3a92 100644 --- a/packages/jest-matcher-utils/src/__tests__/index.test.js +++ b/packages/jest-matcher-utils/src/__tests__/index.test.js @@ -95,13 +95,13 @@ describe('.ensureNumbers()', () => { test('throws error when expected is not a number', () => { expect(() => { ensureNumbers(1, 'not_a_number'); - }).toThrow('Expected value must be a number'); + }).toThrow(/Expected value must be number/); }); test('throws error when actual is not a number', () => { expect(() => { ensureNumbers('not_a_number', 3); - }).toThrow('Received value must be a number'); + }).toThrow(/Received value must be number/); }); }); @@ -115,13 +115,13 @@ describe('.ensureNoExpected()', () => { test('throws error when is not undefined', () => { expect(() => { ensureNoExpected({a: 1}); - }).toThrow('Matcher does not accept any arguments'); + }).toThrow(/Expected value must be omitted or undefined/); }); test('throws error when is not undefined with matcherName', () => { expect(() => { ensureNoExpected({a: 1}, '.toBeDefined'); - }).toThrow('Matcher does not accept any arguments'); + }).toThrow(/Expected value must be omitted or undefined/); }); }); diff --git a/packages/jest-matcher-utils/src/index.js b/packages/jest-matcher-utils/src/index.js index 232b0e33cba9..b740a8b0ed57 100644 --- a/packages/jest-matcher-utils/src/index.js +++ b/packages/jest-matcher-utils/src/index.js @@ -89,27 +89,25 @@ export const printExpected = (value: any) => EXPECTED_COLOR(highlightTrailingWhitespace(stringify(value))); export const printWithType = ( - name: string, - received: any, - print: (value: any) => string, + name: string, // 'Expected' or 'Received' + value: any, + print: (value: any) => string, // printExpected or printReceived ) => { - const type = getType(received); - return ( - name + - ':' + - (type !== 'null' && type !== 'undefined' ? '\n ' + type + ': ' : ' ') + - print(received) - ); + const type = getType(value); + return `${name}${ + type !== 'null' && type !== 'undefined' ? ' ' + type : '' + }: ${print(value)}`; }; export const ensureNoExpected = (expected: any, matcherName: string) => { matcherName || (matcherName = 'This'); if (typeof expected !== 'undefined') { throw new Error( - matcherHint('[.not]' + matcherName, undefined, '') + - '\n\n' + - 'Matcher does not accept any arguments.\n' + - printWithType('Got', expected, printExpected), + matcherErrorMessage( + matcherHint('[.not]' + matcherName, undefined, ''), + 'Expected value must be omitted or undefined', + printWithType('Expected', expected, printExpected), + ), ); } }; @@ -118,10 +116,11 @@ export const ensureActualIsNumber = (actual: any, matcherName: string) => { matcherName || (matcherName = 'This matcher'); if (typeof actual !== 'number') { throw new Error( - matcherHint('[.not]' + matcherName) + - '\n\n' + - `Received value must be a number.\n` + + matcherErrorMessage( + matcherHint('[.not]' + matcherName), + 'Received value must be number', printWithType('Received', actual, printReceived), + ), ); } }; @@ -130,10 +129,11 @@ export const ensureExpectedIsNumber = (expected: any, matcherName: string) => { matcherName || (matcherName = 'This matcher'); if (typeof expected !== 'number') { throw new Error( - matcherHint('[.not]' + matcherName) + - '\n\n' + - `Expected value must be a number.\n` + - printWithType('Got', expected, printExpected), + matcherErrorMessage( + matcherHint('[.not]' + matcherName), + 'Expected value must be number', + printWithType('Expected', expected, printExpected), + ), ); } }; @@ -150,6 +150,12 @@ export const ensureNumbers = ( export const pluralize = (word: string, count: number) => (NUMBERS[count] || count) + ' ' + word + (count === 1 ? '' : 's'); +export const matcherErrorMessage = ( + hint: string, // assertion returned from call to matcherHint + generic: string, // condition which correct value must fulfill + specific: string, // incorrect value returned from call to printWithType +) => `${hint}\n\n${chalk.bold('Matcher error')}: ${generic}\n\n${specific}`; + export const matcherHint = ( matcherName: string, received: string = 'received', From 975ef503ec95e359aef22ac682bb977b80cf6a83 Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Mon, 22 Oct 2018 18:15:58 -0400 Subject: [PATCH 02/10] Added snapshot test for toHaveLength expected length --- .../src/__tests__/__snapshots__/matchers.test.js.snap | 8 ++++++++ packages/expect/src/__tests__/matchers.test.js | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap index e3ebe236c4bd..a292d032e229 100644 --- a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap @@ -2884,6 +2884,14 @@ exports[`.toHaveLength error cases 3`] = ` Received: undefined" `; +exports[`.toHaveLength matcher error expected length 1`] = ` +"expect(received).toHaveLength(expected) + +Matcher error: Expected value must be number + +Expected string: \\"3\\"" +`; + exports[`.toHaveProperty() {error} expect({"a": {"b": {}}}).toHaveProperty('1') 1`] = ` "expect(received).toHaveProperty(path) diff --git a/packages/expect/src/__tests__/matchers.test.js b/packages/expect/src/__tests__/matchers.test.js index 36132f537bb1..05d272487eaf 100644 --- a/packages/expect/src/__tests__/matchers.test.js +++ b/packages/expect/src/__tests__/matchers.test.js @@ -958,6 +958,12 @@ describe('.toHaveLength', () => { jestExpect(undefined).toHaveLength(1), ).toThrowErrorMatchingSnapshot(); }); + + test('matcher error expected length', () => { + expect(() => + jestExpect('abc').toHaveLength('3'), + ).toThrowErrorMatchingSnapshot(); + }) }); describe('.toHaveProperty()', () => { From d4ff133f46383e9bc903d941e61e8b0b2f991557 Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Tue, 23 Oct 2018 09:10:23 -0400 Subject: [PATCH 03/10] Fix prettier lint error --- packages/expect/src/__tests__/matchers.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/expect/src/__tests__/matchers.test.js b/packages/expect/src/__tests__/matchers.test.js index 05d272487eaf..b4fb9f843fc8 100644 --- a/packages/expect/src/__tests__/matchers.test.js +++ b/packages/expect/src/__tests__/matchers.test.js @@ -963,7 +963,7 @@ describe('.toHaveLength', () => { expect(() => jestExpect('abc').toHaveLength('3'), ).toThrowErrorMatchingSnapshot(); - }) + }); }); describe('.toHaveProperty()', () => { From 0e63ecfee2499eddd206fb71048257412cf96664 Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Wed, 24 Oct 2018 10:12:02 -0400 Subject: [PATCH 04/10] Made improvements requested by thymikee --- .../__snapshots__/matchers.test.js.snap | 118 +++++++-------- .../__snapshots__/spy_matchers.test.js.snap | 136 +++++++++--------- .../to_throw_matchers.test.js.snap | 8 +- packages/expect/src/index.js | 4 +- packages/expect/src/matchers.js | 22 +-- packages/expect/src/spy_matchers.js | 2 +- packages/expect/src/to_throw_matchers.js | 4 +- .../src/__tests__/index.test.js | 4 +- packages/jest-matcher-utils/src/index.js | 4 +- 9 files changed, 151 insertions(+), 151 deletions(-) diff --git a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap index a292d032e229..1301c765d43e 100644 --- a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap @@ -10,7 +10,7 @@ Expected received Promise to reject, instead it resolved to value exports[`.rejects fails non-promise value "a" 1`] = ` "expect(received).rejects.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received string: \\"a\\"" `; @@ -18,7 +18,7 @@ Received string: \\"a\\"" exports[`.rejects fails non-promise value [1] 1`] = ` "expect(received).rejects.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received array: [1]" `; @@ -26,7 +26,7 @@ Received array: [1]" exports[`.rejects fails non-promise value [Function anonymous] 1`] = ` "expect(received).rejects.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received function: [Function anonymous]" `; @@ -34,7 +34,7 @@ Received function: [Function anonymous]" exports[`.rejects fails non-promise value {"a": 1} 1`] = ` "expect(received).rejects.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received object: {\\"a\\": 1}" `; @@ -42,7 +42,7 @@ Received object: {\\"a\\": 1}" exports[`.rejects fails non-promise value 4 1`] = ` "expect(received).rejects.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received number: 4" `; @@ -50,7 +50,7 @@ Received number: 4" exports[`.rejects fails non-promise value null 1`] = ` "expect(received).rejects.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received: null" `; @@ -58,7 +58,7 @@ Received: null" exports[`.rejects fails non-promise value true 1`] = ` "expect(received).rejects.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received boolean: true" `; @@ -66,7 +66,7 @@ Received boolean: true" exports[`.rejects fails non-promise value undefined 1`] = ` "expect(received).rejects.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received: undefined" `; @@ -81,7 +81,7 @@ Expected received Promise to resolve, instead it rejected to value exports[`.resolves fails non-promise value "a" 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received string: \\"a\\"" `; @@ -89,7 +89,7 @@ Received string: \\"a\\"" exports[`.resolves fails non-promise value "a" synchronously 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received string: \\"a\\"" `; @@ -97,7 +97,7 @@ Received string: \\"a\\"" exports[`.resolves fails non-promise value [1] 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received array: [1]" `; @@ -105,7 +105,7 @@ Received array: [1]" exports[`.resolves fails non-promise value [1] synchronously 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received array: [1]" `; @@ -113,7 +113,7 @@ Received array: [1]" exports[`.resolves fails non-promise value [Function anonymous] 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received function: [Function anonymous]" `; @@ -121,7 +121,7 @@ Received function: [Function anonymous]" exports[`.resolves fails non-promise value [Function anonymous] synchronously 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received function: [Function anonymous]" `; @@ -129,7 +129,7 @@ Received function: [Function anonymous]" exports[`.resolves fails non-promise value {"a": 1} 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received object: {\\"a\\": 1}" `; @@ -137,7 +137,7 @@ Received object: {\\"a\\": 1}" exports[`.resolves fails non-promise value {"a": 1} synchronously 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received object: {\\"a\\": 1}" `; @@ -145,7 +145,7 @@ Received object: {\\"a\\": 1}" exports[`.resolves fails non-promise value 4 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received number: 4" `; @@ -153,7 +153,7 @@ Received number: 4" exports[`.resolves fails non-promise value 4 synchronously 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received number: 4" `; @@ -161,7 +161,7 @@ Received number: 4" exports[`.resolves fails non-promise value null 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received: null" `; @@ -169,7 +169,7 @@ Received: null" exports[`.resolves fails non-promise value null synchronously 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received: null" `; @@ -177,7 +177,7 @@ Received: null" exports[`.resolves fails non-promise value true 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received boolean: true" `; @@ -185,7 +185,7 @@ Received boolean: true" exports[`.resolves fails non-promise value true synchronously 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received boolean: true" `; @@ -193,7 +193,7 @@ Received boolean: true" exports[`.resolves fails non-promise value undefined 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received: undefined" `; @@ -201,7 +201,7 @@ Received: undefined" exports[`.resolves fails non-promise value undefined synchronously 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be Promise +Matcher error: Received value must be a Promise Received: undefined" `; @@ -1132,7 +1132,7 @@ Received value: Map {}" exports[`.toBeInstanceOf() throws if constructor is not a function 1`] = ` "expect(received).toBeInstanceOf(expected) -Matcher error: Expected value must be function +Matcher error: Expected value must be a function Expected number: 4" `; @@ -1699,7 +1699,7 @@ Not to contain a value equal to: exports[`.toContain(), .toContainEqual() error cases 1`] = ` "expect(received).toContain(expected) -Matcher error: Received value cannot be null or undefined +Matcher error: Received value cannot be null nor undefined Received: null" `; @@ -1707,7 +1707,7 @@ Received: null" exports[`.toContain(), .toContainEqual() error cases for toContainEqual 1`] = ` "expect(received).toContainEqual(expected) -Matcher error: Received value cannot be null or undefined +Matcher error: Received value cannot be null nor undefined Received: null" `; @@ -2863,7 +2863,7 @@ received.length: exports[`.toHaveLength error cases 1`] = ` "expect(received).toHaveLength(expected) -Matcher error: Received value must have length property whose value must be number +Matcher error: Received value must have a length property whose value must be a number Received object: {\\"a\\": 9}" `; @@ -2871,7 +2871,7 @@ Received object: {\\"a\\": 9}" exports[`.toHaveLength error cases 2`] = ` "expect(received).toHaveLength(expected) -Matcher error: Received value must have length property whose value must be number +Matcher error: Received value must have a length property whose value must be a number Received number: 0" `; @@ -2879,7 +2879,7 @@ Received number: 0" exports[`.toHaveLength error cases 3`] = ` "expect(received).toHaveLength(expected) -Matcher error: Received value must have length property whose value must be number +Matcher error: Received value must have a length property whose value must be a number Received: undefined" `; @@ -2887,7 +2887,7 @@ Received: undefined" exports[`.toHaveLength matcher error expected length 1`] = ` "expect(received).toHaveLength(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected string: \\"3\\"" `; @@ -2895,7 +2895,7 @@ Expected string: \\"3\\"" exports[`.toHaveProperty() {error} expect({"a": {"b": {}}}).toHaveProperty('1') 1`] = ` "expect(received).toHaveProperty(path) -Matcher error: Expected path must be string or array +Matcher error: Expected path must be a string or array Expected number: 1" `; @@ -2903,7 +2903,7 @@ Expected number: 1" exports[`.toHaveProperty() {error} expect({"a": {"b": {}}}).toHaveProperty('null') 1`] = ` "expect(received).toHaveProperty(path) -Matcher error: Expected path must be string or array +Matcher error: Expected path must be a string or array Expected: null" `; @@ -2911,7 +2911,7 @@ Expected: null" exports[`.toHaveProperty() {error} expect({"a": {"b": {}}}).toHaveProperty('undefined') 1`] = ` "expect(received).toHaveProperty(path) -Matcher error: Expected path must be string or array +Matcher error: Expected path must be a string or array Expected: undefined" `; @@ -2919,7 +2919,7 @@ Expected: undefined" exports[`.toHaveProperty() {error} expect(null).toHaveProperty('a.b') 1`] = ` "expect(received).toHaveProperty(path) -Matcher error: Received value cannot be null or undefined +Matcher error: Received value cannot be null nor undefined Received: null" `; @@ -2927,7 +2927,7 @@ Received: null" exports[`.toHaveProperty() {error} expect(undefined).toHaveProperty('a') 1`] = ` "expect(received).toHaveProperty(path) -Matcher error: Received value cannot be null or undefined +Matcher error: Received value cannot be null nor undefined Received: undefined" `; @@ -3385,7 +3385,7 @@ Received: exports[`.toMatch() throws if non String actual value passed: [/foo/i, "foo"] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Received value must be string +Matcher error: Received value must be a string Received regexp: /foo/i" `; @@ -3393,7 +3393,7 @@ Received regexp: /foo/i" exports[`.toMatch() throws if non String actual value passed: [[], "foo"] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Received value must be string +Matcher error: Received value must be a string Received array: []" `; @@ -3401,7 +3401,7 @@ Received array: []" exports[`.toMatch() throws if non String actual value passed: [[Function anonymous], "foo"] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Received value must be string +Matcher error: Received value must be a string Received function: [Function anonymous]" `; @@ -3409,7 +3409,7 @@ Received function: [Function anonymous]" exports[`.toMatch() throws if non String actual value passed: [{}, "foo"] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Received value must be string +Matcher error: Received value must be a string Received object: {}" `; @@ -3417,7 +3417,7 @@ Received object: {}" exports[`.toMatch() throws if non String actual value passed: [1, "foo"] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Received value must be string +Matcher error: Received value must be a string Received number: 1" `; @@ -3425,7 +3425,7 @@ Received number: 1" exports[`.toMatch() throws if non String actual value passed: [true, "foo"] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Received value must be string +Matcher error: Received value must be a string Received boolean: true" `; @@ -3433,7 +3433,7 @@ Received boolean: true" exports[`.toMatch() throws if non String actual value passed: [undefined, "foo"] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Received value must be string +Matcher error: Received value must be a string Received: undefined" `; @@ -3441,7 +3441,7 @@ Received: undefined" exports[`.toMatch() throws if non String/RegExp expected value passed: ["foo", []] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Expected value must be string or regular expression +Matcher error: Expected value must be a string or regular expression Expected array: []" `; @@ -3449,7 +3449,7 @@ Expected array: []" exports[`.toMatch() throws if non String/RegExp expected value passed: ["foo", [Function anonymous]] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Expected value must be string or regular expression +Matcher error: Expected value must be a string or regular expression Expected function: [Function anonymous]" `; @@ -3457,7 +3457,7 @@ Expected function: [Function anonymous]" exports[`.toMatch() throws if non String/RegExp expected value passed: ["foo", {}] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Expected value must be string or regular expression +Matcher error: Expected value must be a string or regular expression Expected object: {}" `; @@ -3465,7 +3465,7 @@ Expected object: {}" exports[`.toMatch() throws if non String/RegExp expected value passed: ["foo", 1] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Expected value must be string or regular expression +Matcher error: Expected value must be a string or regular expression Expected number: 1" `; @@ -3473,7 +3473,7 @@ Expected number: 1" exports[`.toMatch() throws if non String/RegExp expected value passed: ["foo", true] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Expected value must be string or regular expression +Matcher error: Expected value must be a string or regular expression Expected boolean: true" `; @@ -3481,7 +3481,7 @@ Expected boolean: true" exports[`.toMatch() throws if non String/RegExp expected value passed: ["foo", undefined] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Expected value must be string or regular expression +Matcher error: Expected value must be a string or regular expression Expected: undefined" `; @@ -4147,7 +4147,7 @@ Received: exports[`toMatchObject() throws expect("44").toMatchObject({}) 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Received value must be non-null object +Matcher error: Received value must be a non-null object Received string: \\"44\\"" `; @@ -4155,7 +4155,7 @@ Received string: \\"44\\"" exports[`toMatchObject() throws expect({}).toMatchObject("some string") 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Expected value must be non-null object +Matcher error: Expected value must be a non-null object Expected string: \\"some string\\"" `; @@ -4163,7 +4163,7 @@ Expected string: \\"some string\\"" exports[`toMatchObject() throws expect({}).toMatchObject(4) 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Expected value must be non-null object +Matcher error: Expected value must be a non-null object Expected number: 4" `; @@ -4171,7 +4171,7 @@ Expected number: 4" exports[`toMatchObject() throws expect({}).toMatchObject(null) 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Expected value must be non-null object +Matcher error: Expected value must be a non-null object Expected: null" `; @@ -4179,7 +4179,7 @@ Expected: null" exports[`toMatchObject() throws expect({}).toMatchObject(true) 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Expected value must be non-null object +Matcher error: Expected value must be a non-null object Expected boolean: true" `; @@ -4187,7 +4187,7 @@ Expected boolean: true" exports[`toMatchObject() throws expect({}).toMatchObject(undefined) 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Expected value must be non-null object +Matcher error: Expected value must be a non-null object Expected: undefined" `; @@ -4195,7 +4195,7 @@ Expected: undefined" exports[`toMatchObject() throws expect(4).toMatchObject({}) 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Received value must be non-null object +Matcher error: Received value must be a non-null object Received number: 4" `; @@ -4203,7 +4203,7 @@ Received number: 4" exports[`toMatchObject() throws expect(null).toMatchObject({}) 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Received value must be non-null object +Matcher error: Received value must be a non-null object Received: null" `; @@ -4211,7 +4211,7 @@ Received: null" exports[`toMatchObject() throws expect(true).toMatchObject({}) 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Received value must be non-null object +Matcher error: Received value must be a non-null object Received boolean: true" `; @@ -4219,7 +4219,7 @@ Received boolean: true" exports[`toMatchObject() throws expect(undefined).toMatchObject({}) 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Received value must be non-null object +Matcher error: Received value must be a non-null object Received: undefined" `; diff --git a/packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap index dd6997f92b8a..56b621d22a3a 100644 --- a/packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap @@ -10,7 +10,7 @@ Expected mock function \\"named-mock\\" to not have been last called with: exports[`lastCalledWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].lastCalledWith() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; @@ -152,7 +152,7 @@ But it was not called" exports[`lastReturnedWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].lastReturnedWith() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; @@ -276,7 +276,7 @@ Expected mock function first call to not have been called with: exports[`nthCalledWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].nthCalledWith() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; @@ -439,7 +439,7 @@ But the first call returned exactly: exports[`nthReturnedWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].nthReturnedWith() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; @@ -581,7 +581,7 @@ Expected mock function not to be called but it was called with: exports[`toBeCalled works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toBeCalled() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; @@ -589,7 +589,7 @@ Received function: [Function fn]" exports[`toBeCalledTimes .not only accepts a number argument 1`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected object: {}" `; @@ -597,7 +597,7 @@ Expected object: {}" exports[`toBeCalledTimes .not only accepts a number argument 2`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected array: []" `; @@ -605,7 +605,7 @@ Expected array: []" exports[`toBeCalledTimes .not only accepts a number argument 3`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected boolean: true" `; @@ -613,7 +613,7 @@ Expected boolean: true" exports[`toBeCalledTimes .not only accepts a number argument 4`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected string: \\"a\\"" `; @@ -621,7 +621,7 @@ Expected string: \\"a\\"" exports[`toBeCalledTimes .not only accepts a number argument 5`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected map: Map {}" `; @@ -629,7 +629,7 @@ Expected map: Map {}" exports[`toBeCalledTimes .not only accepts a number argument 6`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected function: [Function anonymous]" `; @@ -655,7 +655,7 @@ Expected mock function \\"named-mock\\" to have been called two times, exports[`toBeCalledTimes only accepts a number argument 1`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected object: {}" `; @@ -663,7 +663,7 @@ Expected object: {}" exports[`toBeCalledTimes only accepts a number argument 2`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected array: []" `; @@ -671,7 +671,7 @@ Expected array: []" exports[`toBeCalledTimes only accepts a number argument 3`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected boolean: true" `; @@ -679,7 +679,7 @@ Expected boolean: true" exports[`toBeCalledTimes only accepts a number argument 4`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected string: \\"a\\"" `; @@ -687,7 +687,7 @@ Expected string: \\"a\\"" exports[`toBeCalledTimes only accepts a number argument 5`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected map: Map {}" `; @@ -695,7 +695,7 @@ Expected map: Map {}" exports[`toBeCalledTimes only accepts a number argument 6`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected function: [Function anonymous]" `; @@ -709,7 +709,7 @@ Expected mock function not to be called two times, but it was called e exports[`toBeCalledTimes works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toBeCalledTimes() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; @@ -724,7 +724,7 @@ Expected mock function \\"named-mock\\" not to have been called with: exports[`toBeCalledWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toBeCalledWith() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; @@ -886,7 +886,7 @@ Expected mock function not to be called but it was called with: exports[`toHaveBeenCalled works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveBeenCalled() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; @@ -894,7 +894,7 @@ Received function: [Function fn]" exports[`toHaveBeenCalledTimes .not only accepts a number argument 1`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected object: {}" `; @@ -902,7 +902,7 @@ Expected object: {}" exports[`toHaveBeenCalledTimes .not only accepts a number argument 2`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected array: []" `; @@ -910,7 +910,7 @@ Expected array: []" exports[`toHaveBeenCalledTimes .not only accepts a number argument 3`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected boolean: true" `; @@ -918,7 +918,7 @@ Expected boolean: true" exports[`toHaveBeenCalledTimes .not only accepts a number argument 4`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected string: \\"a\\"" `; @@ -926,7 +926,7 @@ Expected string: \\"a\\"" exports[`toHaveBeenCalledTimes .not only accepts a number argument 5`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected map: Map {}" `; @@ -934,7 +934,7 @@ Expected map: Map {}" exports[`toHaveBeenCalledTimes .not only accepts a number argument 6`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected function: [Function anonymous]" `; @@ -960,7 +960,7 @@ Expected mock function \\"named-mock\\" to have been called two times, exports[`toHaveBeenCalledTimes only accepts a number argument 1`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected object: {}" `; @@ -968,7 +968,7 @@ Expected object: {}" exports[`toHaveBeenCalledTimes only accepts a number argument 2`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected array: []" `; @@ -976,7 +976,7 @@ Expected array: []" exports[`toHaveBeenCalledTimes only accepts a number argument 3`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected boolean: true" `; @@ -984,7 +984,7 @@ Expected boolean: true" exports[`toHaveBeenCalledTimes only accepts a number argument 4`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected string: \\"a\\"" `; @@ -992,7 +992,7 @@ Expected string: \\"a\\"" exports[`toHaveBeenCalledTimes only accepts a number argument 5`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected map: Map {}" `; @@ -1000,7 +1000,7 @@ Expected map: Map {}" exports[`toHaveBeenCalledTimes only accepts a number argument 6`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected function: [Function anonymous]" `; @@ -1014,7 +1014,7 @@ Expected mock function not to be called two times, but it was called e exports[`toHaveBeenCalledTimes works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveBeenCalledTimes() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; @@ -1029,7 +1029,7 @@ Expected mock function \\"named-mock\\" not to have been called with: exports[`toHaveBeenCalledWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveBeenCalledWith() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; @@ -1162,7 +1162,7 @@ Expected mock function \\"named-mock\\" to not have been last called with: exports[`toHaveBeenLastCalledWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveBeenLastCalledWith() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; @@ -1307,7 +1307,7 @@ Expected mock function first call to not have been called with: exports[`toHaveBeenNthCalledWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveBeenNthCalledWith() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; @@ -1440,7 +1440,7 @@ But it was not called" exports[`toHaveLastReturnedWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveLastReturnedWith() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; @@ -1591,7 +1591,7 @@ But the first call returned exactly: exports[`toHaveNthReturnedWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveNthReturnedWith() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; @@ -1761,7 +1761,7 @@ Expected mock function not to have returned, but it returned: exports[`toHaveReturned works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveReturned() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; @@ -1769,7 +1769,7 @@ Received function: [Function fn]" exports[`toHaveReturnedTimes .not only accepts a number argument 1`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected object: {}" `; @@ -1777,7 +1777,7 @@ Expected object: {}" exports[`toHaveReturnedTimes .not only accepts a number argument 2`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected array: []" `; @@ -1785,7 +1785,7 @@ Expected array: []" exports[`toHaveReturnedTimes .not only accepts a number argument 3`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected boolean: true" `; @@ -1793,7 +1793,7 @@ Expected boolean: true" exports[`toHaveReturnedTimes .not only accepts a number argument 4`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected string: \\"a\\"" `; @@ -1801,7 +1801,7 @@ Expected string: \\"a\\"" exports[`toHaveReturnedTimes .not only accepts a number argument 5`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected map: Map {}" `; @@ -1809,7 +1809,7 @@ Expected map: Map {}" exports[`toHaveReturnedTimes .not only accepts a number argument 6`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected function: [Function anonymous]" `; @@ -1853,7 +1853,7 @@ Expected mock function \\"named-mock\\" to have returned one time, but exports[`toHaveReturnedTimes only accepts a number argument 1`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected object: {}" `; @@ -1861,7 +1861,7 @@ Expected object: {}" exports[`toHaveReturnedTimes only accepts a number argument 2`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected array: []" `; @@ -1869,7 +1869,7 @@ Expected array: []" exports[`toHaveReturnedTimes only accepts a number argument 3`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected boolean: true" `; @@ -1877,7 +1877,7 @@ Expected boolean: true" exports[`toHaveReturnedTimes only accepts a number argument 4`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected string: \\"a\\"" `; @@ -1885,7 +1885,7 @@ Expected string: \\"a\\"" exports[`toHaveReturnedTimes only accepts a number argument 5`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected map: Map {}" `; @@ -1893,7 +1893,7 @@ Expected map: Map {}" exports[`toHaveReturnedTimes only accepts a number argument 6`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected function: [Function anonymous]" `; @@ -1907,7 +1907,7 @@ Expected mock function not to have returned two times, but it returned exports[`toHaveReturnedTimes works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveReturnedTimes() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; @@ -1939,7 +1939,7 @@ But it did not return." exports[`toHaveReturnedWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveReturnedWith() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; @@ -2119,7 +2119,7 @@ Expected mock function not to have returned, but it returned: exports[`toReturn works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toReturn() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; @@ -2127,7 +2127,7 @@ Received function: [Function fn]" exports[`toReturnTimes .not only accepts a number argument 1`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected object: {}" `; @@ -2135,7 +2135,7 @@ Expected object: {}" exports[`toReturnTimes .not only accepts a number argument 2`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected array: []" `; @@ -2143,7 +2143,7 @@ Expected array: []" exports[`toReturnTimes .not only accepts a number argument 3`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected boolean: true" `; @@ -2151,7 +2151,7 @@ Expected boolean: true" exports[`toReturnTimes .not only accepts a number argument 4`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected string: \\"a\\"" `; @@ -2159,7 +2159,7 @@ Expected string: \\"a\\"" exports[`toReturnTimes .not only accepts a number argument 5`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected map: Map {}" `; @@ -2167,7 +2167,7 @@ Expected map: Map {}" exports[`toReturnTimes .not only accepts a number argument 6`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected function: [Function anonymous]" `; @@ -2211,7 +2211,7 @@ Expected mock function \\"named-mock\\" to have returned one time, but exports[`toReturnTimes only accepts a number argument 1`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected object: {}" `; @@ -2219,7 +2219,7 @@ Expected object: {}" exports[`toReturnTimes only accepts a number argument 2`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected array: []" `; @@ -2227,7 +2227,7 @@ Expected array: []" exports[`toReturnTimes only accepts a number argument 3`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected boolean: true" `; @@ -2235,7 +2235,7 @@ Expected boolean: true" exports[`toReturnTimes only accepts a number argument 4`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected string: \\"a\\"" `; @@ -2243,7 +2243,7 @@ Expected string: \\"a\\"" exports[`toReturnTimes only accepts a number argument 5`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected map: Map {}" `; @@ -2251,7 +2251,7 @@ Expected map: Map {}" exports[`toReturnTimes only accepts a number argument 6`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be number +Matcher error: Expected value must be a number Expected function: [Function anonymous]" `; @@ -2265,7 +2265,7 @@ Expected mock function not to have returned two times, but it returned exports[`toReturnTimes works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toReturnTimes() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; @@ -2297,7 +2297,7 @@ But it did not return." exports[`toReturnWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toReturnWith() -Matcher error: Received value must be mock or spy function +Matcher error: Received value must be a mock or spy function Received function: [Function fn]" `; diff --git a/packages/expect/src/__tests__/__snapshots__/to_throw_matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/to_throw_matchers.test.js.snap index 5c44f7ccd91c..137c7c140956 100644 --- a/packages/expect/src/__tests__/__snapshots__/to_throw_matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/to_throw_matchers.test.js.snap @@ -31,7 +31,7 @@ Instead, it threw: exports[`.toThrow() invalid actual 1`] = ` "expect(received)[.not].toThrow(expected) -Matcher error: Received value must be function +Matcher error: Received value must be a function Received string: \\"a string\\"" `; @@ -39,7 +39,7 @@ Received string: \\"a string\\"" exports[`.toThrow() invalid arguments 1`] = ` "expect(received)[.not].toThrow(expected) -Matcher error: Expected value must be string or regular expression or Error +Matcher error: Expected value must be a string or regular expression or Error Expected number: 111" `; @@ -157,7 +157,7 @@ Instead, it threw: exports[`.toThrowError() invalid actual 1`] = ` "expect(received)[.not].toThrowError(expected) -Matcher error: Received value must be function +Matcher error: Received value must be a function Received string: \\"a string\\"" `; @@ -165,7 +165,7 @@ Received string: \\"a string\\"" exports[`.toThrowError() invalid arguments 1`] = ` "expect(received)[.not].toThrowError(expected) -Matcher error: Expected value must be string or regular expression or Error +Matcher error: Expected value must be a string or regular expression or Error Expected number: 111" `; diff --git a/packages/expect/src/index.js b/packages/expect/src/index.js index 8f048404328c..dc924fed1885 100644 --- a/packages/expect/src/index.js +++ b/packages/expect/src/index.js @@ -147,7 +147,7 @@ const makeResolveMatcher = ( throw new JestAssertionError( matcherUtils.matcherErrorMessage( matcherUtils.matcherHint(matcherStatement, undefined, ''), - 'Received value must be Promise', + 'Received value must be a Promise', matcherUtils.printWithType( 'Received', actual, @@ -188,7 +188,7 @@ const makeRejectMatcher = ( throw new JestAssertionError( matcherUtils.matcherErrorMessage( matcherUtils.matcherHint(matcherStatement, undefined, ''), - 'Received value must be Promise', + 'Received value must be a Promise', matcherUtils.printWithType( 'Received', actual, diff --git a/packages/expect/src/matchers.js b/packages/expect/src/matchers.js index a09efff741be..8bd0752beb01 100644 --- a/packages/expect/src/matchers.js +++ b/packages/expect/src/matchers.js @@ -161,7 +161,7 @@ const matchers: MatchersObject = { matcherHint('.toBeInstanceOf', undefined, undefined, { isNot: this.isNot, }), - 'Expected value must be function', + 'Expected value must be a function', printWithType('Expected', constructor, printExpected), ), ); @@ -288,7 +288,7 @@ const matchers: MatchersObject = { matcherHint('.toContain', undefined, undefined, { isNot: this.isNot, }), - 'Received value cannot be null or undefined', + 'Received value cannot be null nor undefined', printWithType('Received', collection, printReceived), ), ); @@ -341,7 +341,7 @@ const matchers: MatchersObject = { matcherHint('.toContainEqual', undefined, undefined, { isNot: this.isNot, }), - 'Received value cannot be null or undefined', + 'Received value cannot be null nor undefined', printWithType('Received', collection, printReceived), ), ); @@ -412,7 +412,7 @@ const matchers: MatchersObject = { matcherHint('.toHaveLength', undefined, undefined, { isNot: this.isNot, }), - 'Received value must have length property whose value must be number', + 'Received value must have a length property whose value must be a number', printWithType('Received', received, printReceived), ), ); @@ -424,7 +424,7 @@ const matchers: MatchersObject = { matcherHint('.toHaveLength', undefined, undefined, { isNot: this.isNot, }), - 'Expected value must be number', + 'Expected value must be a number', printWithType('Expected', length, printExpected), ), ); @@ -465,7 +465,7 @@ const matchers: MatchersObject = { isNot: this.isNot, secondArgument, }), - 'Received value cannot be null or undefined', + 'Received value cannot be null nor undefined', printWithType('Received', object, printReceived), ), ); @@ -480,7 +480,7 @@ const matchers: MatchersObject = { isNot: this.isNot, secondArgument, }), - 'Expected path must be string or array', + 'Expected path must be a string or array', printWithType('Expected', keyPath, printExpected), ), ); @@ -548,7 +548,7 @@ const matchers: MatchersObject = { matcherHint('.toMatch', undefined, undefined, { isNot: this.isNot, }), - 'Received value must be string', + 'Received value must be a string', printWithType('Received', received, printReceived), ), ); @@ -563,7 +563,7 @@ const matchers: MatchersObject = { matcherHint('.toMatch', undefined, undefined, { isNot: this.isNot, }), - 'Expected value must be string or regular expression', + 'Expected value must be a string or regular expression', printWithType('Expected', expected, printExpected), ), ); @@ -596,7 +596,7 @@ const matchers: MatchersObject = { matcherHint('.toMatchObject', undefined, undefined, { isNot: this.isNot, }), - 'Received value must be non-null object', + 'Received value must be a non-null object', printWithType('Received', receivedObject, printReceived), ), ); @@ -608,7 +608,7 @@ const matchers: MatchersObject = { matcherHint('.toMatchObject', undefined, undefined, { isNot: this.isNot, }), - 'Expected value must be non-null object', + 'Expected value must be a non-null object', printWithType('Expected', expectedObject, printExpected), ), ); diff --git a/packages/expect/src/spy_matchers.js b/packages/expect/src/spy_matchers.js index 7f38c3d9f1f1..a46ab5091a7e 100644 --- a/packages/expect/src/spy_matchers.js +++ b/packages/expect/src/spy_matchers.js @@ -468,7 +468,7 @@ const ensureMock = (mockOrSpy, matcherName) => { throw new Error( matcherErrorMessage( matcherHint('[.not]' + matcherName, 'jest.fn()', ''), - 'Received value must be mock or spy function', + 'Received value must be a mock or spy function', printWithType('Received', mockOrSpy, printReceived), ), ); diff --git a/packages/expect/src/to_throw_matchers.js b/packages/expect/src/to_throw_matchers.js index 9b99356e23b8..5537baec85b1 100644 --- a/packages/expect/src/to_throw_matchers.js +++ b/packages/expect/src/to_throw_matchers.js @@ -39,7 +39,7 @@ export const createMatcher = (matcherName: string, fromPromise?: boolean) => ( throw new Error( matcherErrorMessage( matcherHint('[.not]' + matcherName, undefined, undefined), - 'Received value must be function', + 'Received value must be a function', printWithType('Received', actual, printReceived), ), ); @@ -88,7 +88,7 @@ export const createMatcher = (matcherName: string, fromPromise?: boolean) => ( throw new Error( matcherErrorMessage( matcherHint('[.not]' + matcherName, undefined, undefined), - 'Expected value must be string or regular expression or Error', + 'Expected value must be a string or regular expression or Error', printWithType('Expected', expected, printExpected), ), ); diff --git a/packages/jest-matcher-utils/src/__tests__/index.test.js b/packages/jest-matcher-utils/src/__tests__/index.test.js index 7304185d3a92..9dab6a43689f 100644 --- a/packages/jest-matcher-utils/src/__tests__/index.test.js +++ b/packages/jest-matcher-utils/src/__tests__/index.test.js @@ -95,13 +95,13 @@ describe('.ensureNumbers()', () => { test('throws error when expected is not a number', () => { expect(() => { ensureNumbers(1, 'not_a_number'); - }).toThrow(/Expected value must be number/); + }).toThrow(/Expected value must be a number/); }); test('throws error when actual is not a number', () => { expect(() => { ensureNumbers('not_a_number', 3); - }).toThrow(/Received value must be number/); + }).toThrow(/Received value must be a number/); }); }); diff --git a/packages/jest-matcher-utils/src/index.js b/packages/jest-matcher-utils/src/index.js index b740a8b0ed57..10b63bc096d1 100644 --- a/packages/jest-matcher-utils/src/index.js +++ b/packages/jest-matcher-utils/src/index.js @@ -118,7 +118,7 @@ export const ensureActualIsNumber = (actual: any, matcherName: string) => { throw new Error( matcherErrorMessage( matcherHint('[.not]' + matcherName), - 'Received value must be number', + 'Received value must be a number', printWithType('Received', actual, printReceived), ), ); @@ -131,7 +131,7 @@ export const ensureExpectedIsNumber = (expected: any, matcherName: string) => { throw new Error( matcherErrorMessage( matcherHint('[.not]' + matcherName), - 'Expected value must be number', + 'Expected value must be a number', printWithType('Expected', expected, printExpected), ), ); From 62125b9d97e9fbcca697d3271c820d76262fe366 Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Wed, 24 Oct 2018 16:43:55 -0400 Subject: [PATCH 05/10] Make improvements suggested by SimenB --- .../assertion_counts.test.js.snap | 10 + .../__snapshots__/matchers.test.js.snap | 284 +++++++------ .../__snapshots__/spy_matchers.test.js.snap | 380 +++++++++++------- .../to_throw_matchers.test.js.snap | 20 +- .../src/__tests__/assertion_counts.test.js | 4 +- packages/expect/src/index.js | 4 +- packages/expect/src/matchers.js | 26 +- packages/expect/src/spy_matchers.js | 2 +- packages/expect/src/to_throw_matchers.js | 7 +- .../__snapshots__/index.test.js.snap | 36 ++ .../src/__tests__/index.test.js | 14 +- packages/jest-matcher-utils/src/index.js | 15 +- 12 files changed, 489 insertions(+), 313 deletions(-) create mode 100644 packages/expect/src/__tests__/__snapshots__/assertion_counts.test.js.snap diff --git a/packages/expect/src/__tests__/__snapshots__/assertion_counts.test.js.snap b/packages/expect/src/__tests__/__snapshots__/assertion_counts.test.js.snap new file mode 100644 index 000000000000..c7474a6ec766 --- /dev/null +++ b/packages/expect/src/__tests__/__snapshots__/assertion_counts.test.js.snap @@ -0,0 +1,10 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`.hasAssertions() throws if expected is not undefined 1`] = ` +"expect(received)[.not].hasAssertions() + +Matcher error: expected value must be omitted or undefined + +Expected has type: number +Expected has value: 2" +`; diff --git a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap index 1301c765d43e..8b88d0b82322 100644 --- a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap @@ -10,65 +10,71 @@ Expected received Promise to reject, instead it resolved to value exports[`.rejects fails non-promise value "a" 1`] = ` "expect(received).rejects.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received string: \\"a\\"" +Received has type: string +Received has value: \\"a\\"" `; exports[`.rejects fails non-promise value [1] 1`] = ` "expect(received).rejects.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received array: [1]" +Received has type: array +Received has value: [1]" `; exports[`.rejects fails non-promise value [Function anonymous] 1`] = ` "expect(received).rejects.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received function: [Function anonymous]" +Received has type: function +Received has value: [Function anonymous]" `; exports[`.rejects fails non-promise value {"a": 1} 1`] = ` "expect(received).rejects.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received object: {\\"a\\": 1}" +Received has type: object +Received has value: {\\"a\\": 1}" `; exports[`.rejects fails non-promise value 4 1`] = ` "expect(received).rejects.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received number: 4" +Received has type: number +Received has value: 4" `; exports[`.rejects fails non-promise value null 1`] = ` "expect(received).rejects.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received: null" +Received has value: null" `; exports[`.rejects fails non-promise value true 1`] = ` "expect(received).rejects.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received boolean: true" +Received has type: boolean +Received has value: true" `; exports[`.rejects fails non-promise value undefined 1`] = ` "expect(received).rejects.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received: undefined" +Received has value: undefined" `; exports[`.resolves fails for promise that rejects 1`] = ` @@ -81,129 +87,141 @@ Expected received Promise to resolve, instead it rejected to value exports[`.resolves fails non-promise value "a" 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received string: \\"a\\"" +Received has type: string +Received has value: \\"a\\"" `; exports[`.resolves fails non-promise value "a" synchronously 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received string: \\"a\\"" +Received has type: string +Received has value: \\"a\\"" `; exports[`.resolves fails non-promise value [1] 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received array: [1]" +Received has type: array +Received has value: [1]" `; exports[`.resolves fails non-promise value [1] synchronously 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received array: [1]" +Received has type: array +Received has value: [1]" `; exports[`.resolves fails non-promise value [Function anonymous] 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received function: [Function anonymous]" +Received has type: function +Received has value: [Function anonymous]" `; exports[`.resolves fails non-promise value [Function anonymous] synchronously 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received function: [Function anonymous]" +Received has type: function +Received has value: [Function anonymous]" `; exports[`.resolves fails non-promise value {"a": 1} 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received object: {\\"a\\": 1}" +Received has type: object +Received has value: {\\"a\\": 1}" `; exports[`.resolves fails non-promise value {"a": 1} synchronously 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received object: {\\"a\\": 1}" +Received has type: object +Received has value: {\\"a\\": 1}" `; exports[`.resolves fails non-promise value 4 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received number: 4" +Received has type: number +Received has value: 4" `; exports[`.resolves fails non-promise value 4 synchronously 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received number: 4" +Received has type: number +Received has value: 4" `; exports[`.resolves fails non-promise value null 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received: null" +Received has value: null" `; exports[`.resolves fails non-promise value null synchronously 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received: null" +Received has value: null" `; exports[`.resolves fails non-promise value true 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received boolean: true" +Received has type: boolean +Received has value: true" `; exports[`.resolves fails non-promise value true synchronously 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received boolean: true" +Received has type: boolean +Received has value: true" `; exports[`.resolves fails non-promise value undefined 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received: undefined" +Received has value: undefined" `; exports[`.resolves fails non-promise value undefined synchronously 1`] = ` "expect(received).resolves.toBeDefined() -Matcher error: Received value must be a Promise +Matcher error: received value must be a Promise -Received: undefined" +Received has value: undefined" `; exports[`.toBe() does not crash on circular references 1`] = ` @@ -1132,9 +1150,10 @@ Received value: Map {}" exports[`.toBeInstanceOf() throws if constructor is not a function 1`] = ` "expect(received).toBeInstanceOf(expected) -Matcher error: Expected value must be a function +Matcher error: expected value must be a function -Expected number: 4" +Expected has type: number +Expected has value: 4" `; exports[`.toBeNaN() {pass: true} expect(NaN).toBeNaN() 1`] = ` @@ -1464,17 +1483,17 @@ Received: undefined" exports[`.toBeTruthy(), .toBeFalsy() does not accept arguments 1`] = ` "expect(received)[.not].toBeTruthy() -Matcher error: Expected value must be omitted or undefined +Matcher error: expected value must be omitted or undefined -Expected: null" +Expected has value: null" `; exports[`.toBeTruthy(), .toBeFalsy() does not accept arguments 2`] = ` "expect(received)[.not].toBeFalsy() -Matcher error: Expected value must be omitted or undefined +Matcher error: expected value must be omitted or undefined -Expected: null" +Expected has value: null" `; exports[`.toContain(), .toContainEqual() '"11112111"' contains '"2"' 1`] = ` @@ -1699,17 +1718,17 @@ Not to contain a value equal to: exports[`.toContain(), .toContainEqual() error cases 1`] = ` "expect(received).toContain(expected) -Matcher error: Received value cannot be null nor undefined +Matcher error: received value cannot be null nor undefined -Received: null" +Received has value: null" `; exports[`.toContain(), .toContainEqual() error cases for toContainEqual 1`] = ` "expect(received).toContainEqual(expected) -Matcher error: Received value cannot be null nor undefined +Matcher error: received value cannot be null nor undefined -Received: null" +Received has value: null" `; exports[`.toEqual() {pass: false} expect("Alice").not.toEqual({"asymmetricMatch": [Function asymmetricMatch]}) 1`] = ` @@ -2863,73 +2882,77 @@ received.length: exports[`.toHaveLength error cases 1`] = ` "expect(received).toHaveLength(expected) -Matcher error: Received value must have a length property whose value must be a number +Matcher error: received value must have a length property whose value must be a number -Received object: {\\"a\\": 9}" +Received has type: object +Received has value: {\\"a\\": 9}" `; exports[`.toHaveLength error cases 2`] = ` "expect(received).toHaveLength(expected) -Matcher error: Received value must have a length property whose value must be a number +Matcher error: received value must have a length property whose value must be a number -Received number: 0" +Received has type: number +Received has value: 0" `; exports[`.toHaveLength error cases 3`] = ` "expect(received).toHaveLength(expected) -Matcher error: Received value must have a length property whose value must be a number +Matcher error: received value must have a length property whose value must be a number -Received: undefined" +Received has value: undefined" `; exports[`.toHaveLength matcher error expected length 1`] = ` "expect(received).toHaveLength(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected string: \\"3\\"" +Expected has type: string +Expected has value: \\"3\\"" `; exports[`.toHaveProperty() {error} expect({"a": {"b": {}}}).toHaveProperty('1') 1`] = ` "expect(received).toHaveProperty(path) -Matcher error: Expected path must be a string or array +Matcher error: expected path must be a string or array -Expected number: 1" +Expected has type: number +Expected has value: 1" `; exports[`.toHaveProperty() {error} expect({"a": {"b": {}}}).toHaveProperty('null') 1`] = ` "expect(received).toHaveProperty(path) -Matcher error: Expected path must be a string or array +Matcher error: expected path must be a string or array -Expected: null" +Expected has value: null" `; exports[`.toHaveProperty() {error} expect({"a": {"b": {}}}).toHaveProperty('undefined') 1`] = ` "expect(received).toHaveProperty(path) -Matcher error: Expected path must be a string or array +Matcher error: expected path must be a string or array -Expected: undefined" +Expected has value: undefined" `; exports[`.toHaveProperty() {error} expect(null).toHaveProperty('a.b') 1`] = ` "expect(received).toHaveProperty(path) -Matcher error: Received value cannot be null nor undefined +Matcher error: received value cannot be null nor undefined -Received: null" +Received has value: null" `; exports[`.toHaveProperty() {error} expect(undefined).toHaveProperty('a') 1`] = ` "expect(received).toHaveProperty(path) -Matcher error: Received value cannot be null nor undefined +Matcher error: received value cannot be null nor undefined -Received: undefined" +Received has value: undefined" `; exports[`.toHaveProperty() {pass: false} expect("abc").toHaveProperty('a.b.c') 1`] = ` @@ -3385,105 +3408,116 @@ Received: exports[`.toMatch() throws if non String actual value passed: [/foo/i, "foo"] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Received value must be a string +Matcher error: received value must be a string -Received regexp: /foo/i" +Received has type: regexp +Received has value: /foo/i" `; exports[`.toMatch() throws if non String actual value passed: [[], "foo"] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Received value must be a string +Matcher error: received value must be a string -Received array: []" +Received has type: array +Received has value: []" `; exports[`.toMatch() throws if non String actual value passed: [[Function anonymous], "foo"] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Received value must be a string +Matcher error: received value must be a string -Received function: [Function anonymous]" +Received has type: function +Received has value: [Function anonymous]" `; exports[`.toMatch() throws if non String actual value passed: [{}, "foo"] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Received value must be a string +Matcher error: received value must be a string -Received object: {}" +Received has type: object +Received has value: {}" `; exports[`.toMatch() throws if non String actual value passed: [1, "foo"] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Received value must be a string +Matcher error: received value must be a string -Received number: 1" +Received has type: number +Received has value: 1" `; exports[`.toMatch() throws if non String actual value passed: [true, "foo"] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Received value must be a string +Matcher error: received value must be a string -Received boolean: true" +Received has type: boolean +Received has value: true" `; exports[`.toMatch() throws if non String actual value passed: [undefined, "foo"] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Received value must be a string +Matcher error: received value must be a string -Received: undefined" +Received has value: undefined" `; exports[`.toMatch() throws if non String/RegExp expected value passed: ["foo", []] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Expected value must be a string or regular expression +Matcher error: expected value must be a string or regular expression -Expected array: []" +Expected has type: array +Expected has value: []" `; exports[`.toMatch() throws if non String/RegExp expected value passed: ["foo", [Function anonymous]] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Expected value must be a string or regular expression +Matcher error: expected value must be a string or regular expression -Expected function: [Function anonymous]" +Expected has type: function +Expected has value: [Function anonymous]" `; exports[`.toMatch() throws if non String/RegExp expected value passed: ["foo", {}] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Expected value must be a string or regular expression +Matcher error: expected value must be a string or regular expression -Expected object: {}" +Expected has type: object +Expected has value: {}" `; exports[`.toMatch() throws if non String/RegExp expected value passed: ["foo", 1] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Expected value must be a string or regular expression +Matcher error: expected value must be a string or regular expression -Expected number: 1" +Expected has type: number +Expected has value: 1" `; exports[`.toMatch() throws if non String/RegExp expected value passed: ["foo", true] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Expected value must be a string or regular expression +Matcher error: expected value must be a string or regular expression -Expected boolean: true" +Expected has type: boolean +Expected has value: true" `; exports[`.toMatch() throws if non String/RegExp expected value passed: ["foo", undefined] 1`] = ` "expect(received).toMatch(expected) -Matcher error: Expected value must be a string or regular expression +Matcher error: expected value must be a string or regular expression -Expected: undefined" +Expected has value: undefined" `; exports[`.toMatch() throws: [bar, /foo/] 1`] = ` @@ -4147,79 +4181,85 @@ Received: exports[`toMatchObject() throws expect("44").toMatchObject({}) 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Received value must be a non-null object +Matcher error: received value must be a non-null object -Received string: \\"44\\"" +Received has type: string +Received has value: \\"44\\"" `; exports[`toMatchObject() throws expect({}).toMatchObject("some string") 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Expected value must be a non-null object +Matcher error: expected value must be a non-null object -Expected string: \\"some string\\"" +Expected has type: string +Expected has value: \\"some string\\"" `; exports[`toMatchObject() throws expect({}).toMatchObject(4) 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Expected value must be a non-null object +Matcher error: expected value must be a non-null object -Expected number: 4" +Expected has type: number +Expected has value: 4" `; exports[`toMatchObject() throws expect({}).toMatchObject(null) 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Expected value must be a non-null object +Matcher error: expected value must be a non-null object -Expected: null" +Expected has value: null" `; exports[`toMatchObject() throws expect({}).toMatchObject(true) 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Expected value must be a non-null object +Matcher error: expected value must be a non-null object -Expected boolean: true" +Expected has type: boolean +Expected has value: true" `; exports[`toMatchObject() throws expect({}).toMatchObject(undefined) 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Expected value must be a non-null object +Matcher error: expected value must be a non-null object -Expected: undefined" +Expected has value: undefined" `; exports[`toMatchObject() throws expect(4).toMatchObject({}) 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Received value must be a non-null object +Matcher error: received value must be a non-null object -Received number: 4" +Received has type: number +Received has value: 4" `; exports[`toMatchObject() throws expect(null).toMatchObject({}) 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Received value must be a non-null object +Matcher error: received value must be a non-null object -Received: null" +Received has value: null" `; exports[`toMatchObject() throws expect(true).toMatchObject({}) 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Received value must be a non-null object +Matcher error: received value must be a non-null object -Received boolean: true" +Received has type: boolean +Received has value: true" `; exports[`toMatchObject() throws expect(undefined).toMatchObject({}) 1`] = ` "expect(received).toMatchObject(expected) -Matcher error: Received value must be a non-null object +Matcher error: received value must be a non-null object -Received: undefined" +Received has value: undefined" `; diff --git a/packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap index 56b621d22a3a..b7502f5c84b7 100644 --- a/packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap @@ -10,9 +10,10 @@ Expected mock function \\"named-mock\\" to not have been last called with: exports[`lastCalledWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].lastCalledWith() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`lastCalledWith works when not called 1`] = ` @@ -152,9 +153,10 @@ But it was not called" exports[`lastReturnedWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].lastReturnedWith() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`lastReturnedWith works when not called 1`] = ` @@ -276,9 +278,10 @@ Expected mock function first call to not have been called with: exports[`nthCalledWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].nthCalledWith() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`nthCalledWith works when not called 1`] = ` @@ -439,9 +442,10 @@ But the first call returned exactly: exports[`nthReturnedWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].nthReturnedWith() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`nthReturnedWith works when not called 1`] = ` @@ -545,9 +549,10 @@ But the first call returned exactly: exports[`toBeCalled .not fails with any argument passed 1`] = ` "expect(received)[.not].toBeCalled() -Matcher error: Expected value must be omitted or undefined +Matcher error: expected value must be omitted or undefined -Expected number: 555" +Expected has type: number +Expected has value: 555" `; exports[`toBeCalled .not passes when called 1`] = ` @@ -559,9 +564,10 @@ Expected mock function to have been called, but it was not called." exports[`toBeCalled fails with any argument passed 1`] = ` "expect(received)[.not].toBeCalled() -Matcher error: Expected value must be omitted or undefined +Matcher error: expected value must be omitted or undefined -Expected number: 555" +Expected has type: number +Expected has value: 555" `; exports[`toBeCalled includes the custom mock name in the error message 1`] = ` @@ -581,57 +587,64 @@ Expected mock function not to be called but it was called with: exports[`toBeCalled works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toBeCalled() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`toBeCalledTimes .not only accepts a number argument 1`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected object: {}" +Expected has type: object +Expected has value: {}" `; exports[`toBeCalledTimes .not only accepts a number argument 2`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected array: []" +Expected has type: array +Expected has value: []" `; exports[`toBeCalledTimes .not only accepts a number argument 3`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected boolean: true" +Expected has type: boolean +Expected has value: true" `; exports[`toBeCalledTimes .not only accepts a number argument 4`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected string: \\"a\\"" +Expected has type: string +Expected has value: \\"a\\"" `; exports[`toBeCalledTimes .not only accepts a number argument 5`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected map: Map {}" +Expected has type: map +Expected has value: Map {}" `; exports[`toBeCalledTimes .not only accepts a number argument 6`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected function: [Function anonymous]" +Expected has type: function +Expected has value: [Function anonymous]" `; exports[`toBeCalledTimes .not passes if function called less than expected times 1`] = ` @@ -655,49 +668,55 @@ Expected mock function \\"named-mock\\" to have been called two times, exports[`toBeCalledTimes only accepts a number argument 1`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected object: {}" +Expected has type: object +Expected has value: {}" `; exports[`toBeCalledTimes only accepts a number argument 2`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected array: []" +Expected has type: array +Expected has value: []" `; exports[`toBeCalledTimes only accepts a number argument 3`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected boolean: true" +Expected has type: boolean +Expected has value: true" `; exports[`toBeCalledTimes only accepts a number argument 4`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected string: \\"a\\"" +Expected has type: string +Expected has value: \\"a\\"" `; exports[`toBeCalledTimes only accepts a number argument 5`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected map: Map {}" +Expected has type: map +Expected has value: Map {}" `; exports[`toBeCalledTimes only accepts a number argument 6`] = ` "expect(received)[.not].toBeCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected function: [Function anonymous]" +Expected has type: function +Expected has value: [Function anonymous]" `; exports[`toBeCalledTimes passes if function called equal to expected times 1`] = ` @@ -709,9 +728,10 @@ Expected mock function not to be called two times, but it was called e exports[`toBeCalledTimes works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toBeCalledTimes() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`toBeCalledWith includes the custom mock name in the error message 1`] = ` @@ -724,9 +744,10 @@ Expected mock function \\"named-mock\\" not to have been called with: exports[`toBeCalledWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toBeCalledWith() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`toBeCalledWith works when not called 1`] = ` @@ -850,9 +871,10 @@ Expected mock function to have been called with: exports[`toHaveBeenCalled .not fails with any argument passed 1`] = ` "expect(received)[.not].toHaveBeenCalled() -Matcher error: Expected value must be omitted or undefined +Matcher error: expected value must be omitted or undefined -Expected number: 555" +Expected has type: number +Expected has value: 555" `; exports[`toHaveBeenCalled .not passes when called 1`] = ` @@ -864,9 +886,10 @@ Expected mock function to have been called, but it was not called." exports[`toHaveBeenCalled fails with any argument passed 1`] = ` "expect(received)[.not].toHaveBeenCalled() -Matcher error: Expected value must be omitted or undefined +Matcher error: expected value must be omitted or undefined -Expected number: 555" +Expected has type: number +Expected has value: 555" `; exports[`toHaveBeenCalled includes the custom mock name in the error message 1`] = ` @@ -886,57 +909,64 @@ Expected mock function not to be called but it was called with: exports[`toHaveBeenCalled works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveBeenCalled() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`toHaveBeenCalledTimes .not only accepts a number argument 1`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected object: {}" +Expected has type: object +Expected has value: {}" `; exports[`toHaveBeenCalledTimes .not only accepts a number argument 2`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected array: []" +Expected has type: array +Expected has value: []" `; exports[`toHaveBeenCalledTimes .not only accepts a number argument 3`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected boolean: true" +Expected has type: boolean +Expected has value: true" `; exports[`toHaveBeenCalledTimes .not only accepts a number argument 4`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected string: \\"a\\"" +Expected has type: string +Expected has value: \\"a\\"" `; exports[`toHaveBeenCalledTimes .not only accepts a number argument 5`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected map: Map {}" +Expected has type: map +Expected has value: Map {}" `; exports[`toHaveBeenCalledTimes .not only accepts a number argument 6`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected function: [Function anonymous]" +Expected has type: function +Expected has value: [Function anonymous]" `; exports[`toHaveBeenCalledTimes .not passes if function called less than expected times 1`] = ` @@ -960,49 +990,55 @@ Expected mock function \\"named-mock\\" to have been called two times, exports[`toHaveBeenCalledTimes only accepts a number argument 1`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected object: {}" +Expected has type: object +Expected has value: {}" `; exports[`toHaveBeenCalledTimes only accepts a number argument 2`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected array: []" +Expected has type: array +Expected has value: []" `; exports[`toHaveBeenCalledTimes only accepts a number argument 3`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected boolean: true" +Expected has type: boolean +Expected has value: true" `; exports[`toHaveBeenCalledTimes only accepts a number argument 4`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected string: \\"a\\"" +Expected has type: string +Expected has value: \\"a\\"" `; exports[`toHaveBeenCalledTimes only accepts a number argument 5`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected map: Map {}" +Expected has type: map +Expected has value: Map {}" `; exports[`toHaveBeenCalledTimes only accepts a number argument 6`] = ` "expect(received)[.not].toHaveBeenCalledTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected function: [Function anonymous]" +Expected has type: function +Expected has value: [Function anonymous]" `; exports[`toHaveBeenCalledTimes passes if function called equal to expected times 1`] = ` @@ -1014,9 +1050,10 @@ Expected mock function not to be called two times, but it was called e exports[`toHaveBeenCalledTimes works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveBeenCalledTimes() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`toHaveBeenCalledWith includes the custom mock name in the error message 1`] = ` @@ -1029,9 +1066,10 @@ Expected mock function \\"named-mock\\" not to have been called with: exports[`toHaveBeenCalledWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveBeenCalledWith() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`toHaveBeenCalledWith works when not called 1`] = ` @@ -1162,9 +1200,10 @@ Expected mock function \\"named-mock\\" to not have been last called with: exports[`toHaveBeenLastCalledWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveBeenLastCalledWith() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`toHaveBeenLastCalledWith works when not called 1`] = ` @@ -1307,9 +1346,10 @@ Expected mock function first call to not have been called with: exports[`toHaveBeenNthCalledWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveBeenNthCalledWith() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`toHaveBeenNthCalledWith works when not called 1`] = ` @@ -1440,9 +1480,10 @@ But it was not called" exports[`toHaveLastReturnedWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveLastReturnedWith() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`toHaveLastReturnedWith works when not called 1`] = ` @@ -1591,9 +1632,10 @@ But the first call returned exactly: exports[`toHaveNthReturnedWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveNthReturnedWith() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`toHaveNthReturnedWith works when not called 1`] = ` @@ -1697,9 +1739,10 @@ But the first call returned exactly: exports[`toHaveReturned .not fails with any argument passed 1`] = ` "expect(received)[.not].toHaveReturned() -Matcher error: Expected value must be omitted or undefined +Matcher error: expected value must be omitted or undefined -Expected number: 555" +Expected has type: number +Expected has value: 555" `; exports[`toHaveReturned .not passes when a call throws undefined 1`] = ` @@ -1723,9 +1766,10 @@ Expected mock function to have returned." exports[`toHaveReturned fails with any argument passed 1`] = ` "expect(received)[.not].toHaveReturned() -Matcher error: Expected value must be omitted or undefined +Matcher error: expected value must be omitted or undefined -Expected number: 555" +Expected has type: number +Expected has value: 555" `; exports[`toHaveReturned includes the custom mock name in the error message 1`] = ` @@ -1761,57 +1805,64 @@ Expected mock function not to have returned, but it returned: exports[`toHaveReturned works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveReturned() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`toHaveReturnedTimes .not only accepts a number argument 1`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected object: {}" +Expected has type: object +Expected has value: {}" `; exports[`toHaveReturnedTimes .not only accepts a number argument 2`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected array: []" +Expected has type: array +Expected has value: []" `; exports[`toHaveReturnedTimes .not only accepts a number argument 3`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected boolean: true" +Expected has type: boolean +Expected has value: true" `; exports[`toHaveReturnedTimes .not only accepts a number argument 4`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected string: \\"a\\"" +Expected has type: string +Expected has value: \\"a\\"" `; exports[`toHaveReturnedTimes .not only accepts a number argument 5`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected map: Map {}" +Expected has type: map +Expected has value: Map {}" `; exports[`toHaveReturnedTimes .not only accepts a number argument 6`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected function: [Function anonymous]" +Expected has type: function +Expected has value: [Function anonymous]" `; exports[`toHaveReturnedTimes .not passes if function called less than expected times 1`] = ` @@ -1853,49 +1904,55 @@ Expected mock function \\"named-mock\\" to have returned one time, but exports[`toHaveReturnedTimes only accepts a number argument 1`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected object: {}" +Expected has type: object +Expected has value: {}" `; exports[`toHaveReturnedTimes only accepts a number argument 2`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected array: []" +Expected has type: array +Expected has value: []" `; exports[`toHaveReturnedTimes only accepts a number argument 3`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected boolean: true" +Expected has type: boolean +Expected has value: true" `; exports[`toHaveReturnedTimes only accepts a number argument 4`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected string: \\"a\\"" +Expected has type: string +Expected has value: \\"a\\"" `; exports[`toHaveReturnedTimes only accepts a number argument 5`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected map: Map {}" +Expected has type: map +Expected has value: Map {}" `; exports[`toHaveReturnedTimes only accepts a number argument 6`] = ` "expect(received)[.not].toHaveReturnedTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected function: [Function anonymous]" +Expected has type: function +Expected has value: [Function anonymous]" `; exports[`toHaveReturnedTimes passes if function returned equal to expected times 1`] = ` @@ -1907,9 +1964,10 @@ Expected mock function not to have returned two times, but it returned exports[`toHaveReturnedTimes works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveReturnedTimes() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`toHaveReturnedWith a call that throws is not considered to have returned 1`] = ` @@ -1939,9 +1997,10 @@ But it did not return." exports[`toHaveReturnedWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toHaveReturnedWith() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`toHaveReturnedWith works when not called 1`] = ` @@ -2055,9 +2114,10 @@ But it returned exactly: exports[`toReturn .not fails with any argument passed 1`] = ` "expect(received)[.not].toReturn() -Matcher error: Expected value must be omitted or undefined +Matcher error: expected value must be omitted or undefined -Expected number: 555" +Expected has type: number +Expected has value: 555" `; exports[`toReturn .not passes when a call throws undefined 1`] = ` @@ -2081,9 +2141,10 @@ Expected mock function to have returned." exports[`toReturn fails with any argument passed 1`] = ` "expect(received)[.not].toReturn() -Matcher error: Expected value must be omitted or undefined +Matcher error: expected value must be omitted or undefined -Expected number: 555" +Expected has type: number +Expected has value: 555" `; exports[`toReturn includes the custom mock name in the error message 1`] = ` @@ -2119,57 +2180,64 @@ Expected mock function not to have returned, but it returned: exports[`toReturn works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toReturn() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`toReturnTimes .not only accepts a number argument 1`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected object: {}" +Expected has type: object +Expected has value: {}" `; exports[`toReturnTimes .not only accepts a number argument 2`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected array: []" +Expected has type: array +Expected has value: []" `; exports[`toReturnTimes .not only accepts a number argument 3`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected boolean: true" +Expected has type: boolean +Expected has value: true" `; exports[`toReturnTimes .not only accepts a number argument 4`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected string: \\"a\\"" +Expected has type: string +Expected has value: \\"a\\"" `; exports[`toReturnTimes .not only accepts a number argument 5`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected map: Map {}" +Expected has type: map +Expected has value: Map {}" `; exports[`toReturnTimes .not only accepts a number argument 6`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected function: [Function anonymous]" +Expected has type: function +Expected has value: [Function anonymous]" `; exports[`toReturnTimes .not passes if function called less than expected times 1`] = ` @@ -2211,49 +2279,55 @@ Expected mock function \\"named-mock\\" to have returned one time, but exports[`toReturnTimes only accepts a number argument 1`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected object: {}" +Expected has type: object +Expected has value: {}" `; exports[`toReturnTimes only accepts a number argument 2`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected array: []" +Expected has type: array +Expected has value: []" `; exports[`toReturnTimes only accepts a number argument 3`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected boolean: true" +Expected has type: boolean +Expected has value: true" `; exports[`toReturnTimes only accepts a number argument 4`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected string: \\"a\\"" +Expected has type: string +Expected has value: \\"a\\"" `; exports[`toReturnTimes only accepts a number argument 5`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected map: Map {}" +Expected has type: map +Expected has value: Map {}" `; exports[`toReturnTimes only accepts a number argument 6`] = ` "expect(received)[.not].toReturnTimes(expected) -Matcher error: Expected value must be a number +Matcher error: expected value must be a number -Expected function: [Function anonymous]" +Expected has type: function +Expected has value: [Function anonymous]" `; exports[`toReturnTimes passes if function returned equal to expected times 1`] = ` @@ -2265,9 +2339,10 @@ Expected mock function not to have returned two times, but it returned exports[`toReturnTimes works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toReturnTimes() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`toReturnWith a call that throws is not considered to have returned 1`] = ` @@ -2297,9 +2372,10 @@ But it did not return." exports[`toReturnWith works only on spies or jest.fn 1`] = ` "expect(jest.fn())[.not].toReturnWith() -Matcher error: Received value must be a mock or spy function +Matcher error: received value must be a mock or spy function -Received function: [Function fn]" +Received has type: function +Received has value: [Function fn]" `; exports[`toReturnWith works when not called 1`] = ` diff --git a/packages/expect/src/__tests__/__snapshots__/to_throw_matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/to_throw_matchers.test.js.snap index 137c7c140956..8ce9e200485f 100644 --- a/packages/expect/src/__tests__/__snapshots__/to_throw_matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/to_throw_matchers.test.js.snap @@ -31,17 +31,19 @@ Instead, it threw: exports[`.toThrow() invalid actual 1`] = ` "expect(received)[.not].toThrow(expected) -Matcher error: Received value must be a function +Matcher error: received value must be a function -Received string: \\"a string\\"" +Received has type: string +Received has value: \\"a string\\"" `; exports[`.toThrow() invalid arguments 1`] = ` "expect(received)[.not].toThrow(expected) -Matcher error: Expected value must be a string or regular expression or Error +Matcher error: expected value must be a string or regular expression or Error -Expected number: 111" +Expected has type: number +Expected has value: 111" `; exports[`.toThrow() promise/async throws if Error-like object is returned did not throw at all 1`] = ` @@ -157,17 +159,19 @@ Instead, it threw: exports[`.toThrowError() invalid actual 1`] = ` "expect(received)[.not].toThrowError(expected) -Matcher error: Received value must be a function +Matcher error: received value must be a function -Received string: \\"a string\\"" +Received has type: string +Received has value: \\"a string\\"" `; exports[`.toThrowError() invalid arguments 1`] = ` "expect(received)[.not].toThrowError(expected) -Matcher error: Expected value must be a string or regular expression or Error +Matcher error: expected value must be a string or regular expression or Error -Expected number: 111" +Expected has type: number +Expected has value: 111" `; exports[`.toThrowError() promise/async throws if Error-like object is returned did not throw at all 1`] = ` diff --git a/packages/expect/src/__tests__/assertion_counts.test.js b/packages/expect/src/__tests__/assertion_counts.test.js index f6b3bdab6adf..52a595615e34 100644 --- a/packages/expect/src/__tests__/assertion_counts.test.js +++ b/packages/expect/src/__tests__/assertion_counts.test.js @@ -34,10 +34,10 @@ describe('.hasAssertions()', () => { jestExpect('a').toBe('a'); }); - it('throws if passed parameters', () => { + it('throws if expected is not undefined', () => { jestExpect(() => { jestExpect.hasAssertions(2); - }).toThrow(/Expected value must be omitted or undefined/); + }).toThrowErrorMatchingSnapshot(); }); it('hasAssertions not leaking to global state', () => {}); diff --git a/packages/expect/src/index.js b/packages/expect/src/index.js index dc924fed1885..c23cd01d343c 100644 --- a/packages/expect/src/index.js +++ b/packages/expect/src/index.js @@ -147,7 +147,7 @@ const makeResolveMatcher = ( throw new JestAssertionError( matcherUtils.matcherErrorMessage( matcherUtils.matcherHint(matcherStatement, undefined, ''), - 'Received value must be a Promise', + `${matcherUtils.RECEIVED_COLOR('received')} value must be a Promise`, matcherUtils.printWithType( 'Received', actual, @@ -188,7 +188,7 @@ const makeRejectMatcher = ( throw new JestAssertionError( matcherUtils.matcherErrorMessage( matcherUtils.matcherHint(matcherStatement, undefined, ''), - 'Received value must be a Promise', + `${matcherUtils.RECEIVED_COLOR('received')} value must be a Promise`, matcherUtils.printWithType( 'Received', actual, diff --git a/packages/expect/src/matchers.js b/packages/expect/src/matchers.js index 8bd0752beb01..624dc559f132 100644 --- a/packages/expect/src/matchers.js +++ b/packages/expect/src/matchers.js @@ -161,7 +161,7 @@ const matchers: MatchersObject = { matcherHint('.toBeInstanceOf', undefined, undefined, { isNot: this.isNot, }), - 'Expected value must be a function', + `${EXPECTED_COLOR('expected')} value must be a function`, printWithType('Expected', constructor, printExpected), ), ); @@ -288,7 +288,7 @@ const matchers: MatchersObject = { matcherHint('.toContain', undefined, undefined, { isNot: this.isNot, }), - 'Received value cannot be null nor undefined', + `${RECEIVED_COLOR('received')} value cannot be null nor undefined`, printWithType('Received', collection, printReceived), ), ); @@ -341,7 +341,7 @@ const matchers: MatchersObject = { matcherHint('.toContainEqual', undefined, undefined, { isNot: this.isNot, }), - 'Received value cannot be null nor undefined', + `${RECEIVED_COLOR('received')} value cannot be null nor undefined`, printWithType('Received', collection, printReceived), ), ); @@ -412,7 +412,9 @@ const matchers: MatchersObject = { matcherHint('.toHaveLength', undefined, undefined, { isNot: this.isNot, }), - 'Received value must have a length property whose value must be a number', + `${RECEIVED_COLOR( + 'received', + )} value must have a length property whose value must be a number`, printWithType('Received', received, printReceived), ), ); @@ -424,7 +426,7 @@ const matchers: MatchersObject = { matcherHint('.toHaveLength', undefined, undefined, { isNot: this.isNot, }), - 'Expected value must be a number', + `${EXPECTED_COLOR('expected')} value must be a number`, printWithType('Expected', length, printExpected), ), ); @@ -465,7 +467,7 @@ const matchers: MatchersObject = { isNot: this.isNot, secondArgument, }), - 'Received value cannot be null nor undefined', + `${RECEIVED_COLOR('received')} value cannot be null nor undefined`, printWithType('Received', object, printReceived), ), ); @@ -480,7 +482,7 @@ const matchers: MatchersObject = { isNot: this.isNot, secondArgument, }), - 'Expected path must be a string or array', + `${EXPECTED_COLOR('expected')} path must be a string or array`, printWithType('Expected', keyPath, printExpected), ), ); @@ -548,7 +550,7 @@ const matchers: MatchersObject = { matcherHint('.toMatch', undefined, undefined, { isNot: this.isNot, }), - 'Received value must be a string', + `${RECEIVED_COLOR('received')} value must be a string`, printWithType('Received', received, printReceived), ), ); @@ -563,7 +565,9 @@ const matchers: MatchersObject = { matcherHint('.toMatch', undefined, undefined, { isNot: this.isNot, }), - 'Expected value must be a string or regular expression', + `${EXPECTED_COLOR( + 'expected', + )} value must be a string or regular expression`, printWithType('Expected', expected, printExpected), ), ); @@ -596,7 +600,7 @@ const matchers: MatchersObject = { matcherHint('.toMatchObject', undefined, undefined, { isNot: this.isNot, }), - 'Received value must be a non-null object', + `${RECEIVED_COLOR('received')} value must be a non-null object`, printWithType('Received', receivedObject, printReceived), ), ); @@ -608,7 +612,7 @@ const matchers: MatchersObject = { matcherHint('.toMatchObject', undefined, undefined, { isNot: this.isNot, }), - 'Expected value must be a non-null object', + `${EXPECTED_COLOR('expected')} value must be a non-null object`, printWithType('Expected', expectedObject, printExpected), ), ); diff --git a/packages/expect/src/spy_matchers.js b/packages/expect/src/spy_matchers.js index a46ab5091a7e..da4e4f1680ba 100644 --- a/packages/expect/src/spy_matchers.js +++ b/packages/expect/src/spy_matchers.js @@ -468,7 +468,7 @@ const ensureMock = (mockOrSpy, matcherName) => { throw new Error( matcherErrorMessage( matcherHint('[.not]' + matcherName, 'jest.fn()', ''), - 'Received value must be a mock or spy function', + `${RECEIVED_COLOR('received')} value must be a mock or spy function`, printWithType('Received', mockOrSpy, printReceived), ), ); diff --git a/packages/expect/src/to_throw_matchers.js b/packages/expect/src/to_throw_matchers.js index 5537baec85b1..14980d003922 100644 --- a/packages/expect/src/to_throw_matchers.js +++ b/packages/expect/src/to_throw_matchers.js @@ -13,6 +13,7 @@ import getType from 'jest-get-type'; import {escapeStrForRegex} from 'jest-regex-util'; import {formatStackTrace, separateMessageFromStack} from 'jest-message-util'; import { + EXPECTED_COLOR, RECEIVED_COLOR, highlightTrailingWhitespace, matcherErrorMessage, @@ -39,7 +40,7 @@ export const createMatcher = (matcherName: string, fromPromise?: boolean) => ( throw new Error( matcherErrorMessage( matcherHint('[.not]' + matcherName, undefined, undefined), - 'Received value must be a function', + `${RECEIVED_COLOR('received')} value must be a function`, printWithType('Received', actual, printReceived), ), ); @@ -88,7 +89,9 @@ export const createMatcher = (matcherName: string, fromPromise?: boolean) => ( throw new Error( matcherErrorMessage( matcherHint('[.not]' + matcherName, undefined, undefined), - 'Expected value must be a string or regular expression or Error', + `${EXPECTED_COLOR( + 'expected', + )} value must be a string or regular expression or Error`, printWithType('Expected', expected, printExpected), ), ); 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..fb80b64d1896 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 @@ -1,5 +1,41 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`.ensureNoExpected() throws error when expected is not undefined 1`] = ` +"expect(received)[.not]This() + +Matcher error: expected value must be omitted or undefined + +Expected has type: object +Expected has value: {\\"a\\": 1}" +`; + +exports[`.ensureNoExpected() throws error when expected is not undefined with matcherName 1`] = ` +"expect(received)[.not].toBeDefined() + +Matcher error: expected value must be omitted or undefined + +Expected has type: object +Expected has value: {\\"a\\": 1}" +`; + +exports[`.ensureNumbers() throws error when expected is not a number 1`] = ` +"expect(received)[.not]This matcher(expected) + +Matcher error: expected value must be a number + +Expected has type: string +Expected has value: \\"not_a_number\\"" +`; + +exports[`.ensureNumbers() throws error when received is not a number 1`] = ` +"expect(received)[.not]This matcher(expected) + +Matcher error: received value must be a number + +Received has type: string +Received has value: \\"not_a_number\\"" +`; + exports[`.stringify() reduces maxDepth if stringifying very large objects 1`] = `"{\\"a\\": 1, \\"b\\": [Object]}"`; exports[`.stringify() reduces maxDepth if stringifying very large objects 2`] = `"{\\"a\\": 1, \\"b\\": {\\"0\\": \\"test\\", \\"1\\": \\"test\\", \\"2\\": \\"test\\", \\"3\\": \\"test\\", \\"4\\": \\"test\\", \\"5\\": \\"test\\", \\"6\\": \\"test\\", \\"7\\": \\"test\\", \\"8\\": \\"test\\", \\"9\\": \\"test\\"}}"`; diff --git a/packages/jest-matcher-utils/src/__tests__/index.test.js b/packages/jest-matcher-utils/src/__tests__/index.test.js index 9dab6a43689f..11843c3aceb8 100644 --- a/packages/jest-matcher-utils/src/__tests__/index.test.js +++ b/packages/jest-matcher-utils/src/__tests__/index.test.js @@ -95,13 +95,13 @@ describe('.ensureNumbers()', () => { test('throws error when expected is not a number', () => { expect(() => { ensureNumbers(1, 'not_a_number'); - }).toThrow(/Expected value must be a number/); + }).toThrowErrorMatchingSnapshot(); }); - test('throws error when actual is not a number', () => { + test('throws error when received is not a number', () => { expect(() => { ensureNumbers('not_a_number', 3); - }).toThrow(/Received value must be a number/); + }).toThrowErrorMatchingSnapshot(); }); }); @@ -112,16 +112,16 @@ describe('.ensureNoExpected()', () => { }).not.toThrow(); }); - test('throws error when is not undefined', () => { + test('throws error when expected is not undefined', () => { expect(() => { ensureNoExpected({a: 1}); - }).toThrow(/Expected value must be omitted or undefined/); + }).toThrowErrorMatchingSnapshot(); }); - test('throws error when is not undefined with matcherName', () => { + test('throws error when expected is not undefined with matcherName', () => { expect(() => { ensureNoExpected({a: 1}, '.toBeDefined'); - }).toThrow(/Expected value must be omitted or undefined/); + }).toThrowErrorMatchingSnapshot(); }); }); diff --git a/packages/jest-matcher-utils/src/index.js b/packages/jest-matcher-utils/src/index.js index 10b63bc096d1..03f0e6369826 100644 --- a/packages/jest-matcher-utils/src/index.js +++ b/packages/jest-matcher-utils/src/index.js @@ -94,9 +94,12 @@ export const printWithType = ( print: (value: any) => string, // printExpected or printReceived ) => { const type = getType(value); - return `${name}${ - type !== 'null' && type !== 'undefined' ? ' ' + type : '' - }: ${print(value)}`; + const hasType = + type !== 'null' && type !== 'undefined' + ? `${name} has type: ${type}\n` + : ''; + const hasValue = `${name} has value: ${print(value)}`; + return hasType + hasValue; }; export const ensureNoExpected = (expected: any, matcherName: string) => { @@ -105,7 +108,7 @@ export const ensureNoExpected = (expected: any, matcherName: string) => { throw new Error( matcherErrorMessage( matcherHint('[.not]' + matcherName, undefined, ''), - 'Expected value must be omitted or undefined', + `${EXPECTED_COLOR('expected')} value must be omitted or undefined`, printWithType('Expected', expected, printExpected), ), ); @@ -118,7 +121,7 @@ export const ensureActualIsNumber = (actual: any, matcherName: string) => { throw new Error( matcherErrorMessage( matcherHint('[.not]' + matcherName), - 'Received value must be a number', + `${RECEIVED_COLOR('received')} value must be a number`, printWithType('Received', actual, printReceived), ), ); @@ -131,7 +134,7 @@ export const ensureExpectedIsNumber = (expected: any, matcherName: string) => { throw new Error( matcherErrorMessage( matcherHint('[.not]' + matcherName), - 'Expected value must be a number', + `${EXPECTED_COLOR('expected')} value must be a number`, printWithType('Expected', expected, printExpected), ), ); From 4b3bfc1b86cf13776b9348938aa14db405eb67cf Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Thu, 25 Oct 2018 09:22:40 -0400 Subject: [PATCH 06/10] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b1bda867c94..b9ce880e7ff6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - `[jest-runtime]` Remove `cacheDirectory` from `ignorePattern` for `HasteMap` if not necessary ([#7166](https://github.com/facebook/jest/pull/7166)) - `[jest-validate]` Add syntax to validate multiple permitted types ([#7207](https://github.com/facebook/jest/pull/7207)) - `[babel-preset-jest]` [**BREAKING**] Export a function instead of an object for Babel 7 compatibility ([#7203](https://github.com/facebook/jest/pull/7203)) +- `[expect/jest-matcher-utils]` Improve report when assertion fails, part 4 ([#7241](https://github.com/facebook/jest/pull/7241)) ### Fixes From 20ca1aa2b1af5ddae6dfe274a2872d8fd8390b0c Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Sun, 18 Nov 2018 15:38:47 -0500 Subject: [PATCH 07/10] Save the change to resolve the other merge conflict --- CHANGELOG.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ece41f84a2e..c5610243ec52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +25,6 @@ - `[jest-validate]` Add syntax to validate multiple permitted types ([#7207](https://github.com/facebook/jest/pull/7207)) - `[jest-config]` Accept an array as as well as a string for `testRegex`([#7209]https://github.com/facebook/jest/pull/7209)) - `[babel-preset-jest]` [**BREAKING**] Export a function instead of an object for Babel 7 compatibility ([#7203](https://github.com/facebook/jest/pull/7203)) -<<<<<<< HEAD - `[expect/jest-matcher-utils]` Improve report when assertion fails, part 4 ([#7241](https://github.com/facebook/jest/pull/7241)) - `[expect]` Check constructor equality in .toStrictEqual() ([#7005](https://github.com/facebook/jest/pull/7005)) - `[jest-util]` Add `jest.getTimerCount()` to get the count of scheduled fake timers ([#7285](https://github.com/facebook/jest/pull/7285)) @@ -33,11 +32,6 @@ - `[jest-haste-map]` [**BREAKING**] Expose relative paths when getting the file iterator ([#7321](https://github.com/facebook/jest/pull/7321)) - `[jest-haste-map]` Accept a `getCacheKey` method in `hasteImplModulePath` modules to reset the cache when the logic changes ([#7350](https://github.com/facebook/jest/pull/7350)) - `[jest-config]` Add `haste.computeSha1` option to compute the sha-1 of the files in the haste map ([#7345](https://github.com/facebook/jest/pull/7345)) -======= -- `[expect]` Check constructor equality in .toStrictEqual() ([#7005](https://github.com/facebook/jest/pull/7005)) -- `[jest-util]` Add `jest.getTimerCount()` to get the count of scheduled fake timers ([#7285](https://github.com/facebook/jest/pull/7285)) -- `[expect/jest-matcher-utils]` Improve report when assertion fails, part 4 ([#7241](https://github.com/facebook/jest/pull/7241)) ->>>>>>> bbcd2eb72eba6ecb30e58cb35fa81df108a319c7 ### Fixes From 42e0c4205c44dbf743d9dd3312a85fe45c5ea50c Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Sun, 18 Nov 2018 16:20:44 -0500 Subject: [PATCH 08/10] Deleted assertion_counts.test.js.snap --- .../__snapshots__/assertion_counts.test.js.snap | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 packages/expect/src/__tests__/__snapshots__/assertion_counts.test.js.snap diff --git a/packages/expect/src/__tests__/__snapshots__/assertion_counts.test.js.snap b/packages/expect/src/__tests__/__snapshots__/assertion_counts.test.js.snap deleted file mode 100644 index c7474a6ec766..000000000000 --- a/packages/expect/src/__tests__/__snapshots__/assertion_counts.test.js.snap +++ /dev/null @@ -1,10 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`.hasAssertions() throws if expected is not undefined 1`] = ` -"expect(received)[.not].hasAssertions() - -Matcher error: expected value must be omitted or undefined - -Expected has type: number -Expected has value: 2" -`; From 8779d9426fe64947419410bb7f5232cb214588da Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Wed, 12 Dec 2018 13:05:15 -0500 Subject: [PATCH 09/10] Replace cannot with must not --- .../src/__tests__/__snapshots__/matchers.test.js.snap | 8 ++++---- packages/expect/src/matchers.js | 6 +++--- 2 files changed, 7 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 4647a14ca6b2..f1503dbd4ff4 100644 --- a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap @@ -1758,7 +1758,7 @@ Not to contain a value equal to: exports[`.toContain(), .toContainEqual() error cases 1`] = ` "expect(received).toContain(expected) -Matcher error: received value cannot be null nor undefined +Matcher error: received value must not be null nor undefined Received has value: null" `; @@ -1766,7 +1766,7 @@ Received has value: null" exports[`.toContain(), .toContainEqual() error cases for toContainEqual 1`] = ` "expect(received).toContainEqual(expected) -Matcher error: received value cannot be null nor undefined +Matcher error: received value must not be null nor undefined Received has value: null" `; @@ -2982,7 +2982,7 @@ Expected has value: undefined" exports[`.toHaveProperty() {error} expect(null).toHaveProperty('a.b') 1`] = ` "expect(received).toHaveProperty(path) -Matcher error: received value cannot be null nor undefined +Matcher error: received value must not be null nor undefined Received has value: null" `; @@ -2990,7 +2990,7 @@ Received has value: null" exports[`.toHaveProperty() {error} expect(undefined).toHaveProperty('a') 1`] = ` "expect(received).toHaveProperty(path) -Matcher error: received value cannot be null nor undefined +Matcher error: received value must not be null nor undefined Received has value: undefined" `; diff --git a/packages/expect/src/matchers.js b/packages/expect/src/matchers.js index 33fb8d1c40eb..c120e5cff6dc 100644 --- a/packages/expect/src/matchers.js +++ b/packages/expect/src/matchers.js @@ -294,7 +294,7 @@ const matchers: MatchersObject = { matcherHint('.toContain', undefined, undefined, { isNot: this.isNot, }), - `${RECEIVED_COLOR('received')} value cannot be null nor undefined`, + `${RECEIVED_COLOR('received')} value must not be null nor undefined`, printWithType('Received', collection, printReceived), ), ); @@ -347,7 +347,7 @@ const matchers: MatchersObject = { matcherHint('.toContainEqual', undefined, undefined, { isNot: this.isNot, }), - `${RECEIVED_COLOR('received')} value cannot be null nor undefined`, + `${RECEIVED_COLOR('received')} value must not be null nor undefined`, printWithType('Received', collection, printReceived), ), ); @@ -473,7 +473,7 @@ const matchers: MatchersObject = { isNot: this.isNot, secondArgument, }), - `${RECEIVED_COLOR('received')} value cannot be null nor undefined`, + `${RECEIVED_COLOR('received')} value must not be null nor undefined`, printWithType('Received', object, printReceived), ), ); From 09e5bc9270926a5cd715bd892f42b38608274e15 Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Wed, 12 Dec 2018 13:09:59 -0500 Subject: [PATCH 10/10] Fix prettier lint error --- packages/expect/src/matchers.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/expect/src/matchers.js b/packages/expect/src/matchers.js index c120e5cff6dc..1222b664bc3e 100644 --- a/packages/expect/src/matchers.js +++ b/packages/expect/src/matchers.js @@ -294,7 +294,9 @@ const matchers: MatchersObject = { matcherHint('.toContain', undefined, undefined, { isNot: this.isNot, }), - `${RECEIVED_COLOR('received')} value must not be null nor undefined`, + `${RECEIVED_COLOR( + 'received', + )} value must not be null nor undefined`, printWithType('Received', collection, printReceived), ), ); @@ -347,7 +349,9 @@ const matchers: MatchersObject = { matcherHint('.toContainEqual', undefined, undefined, { isNot: this.isNot, }), - `${RECEIVED_COLOR('received')} value must not be null nor undefined`, + `${RECEIVED_COLOR( + 'received', + )} value must not be null nor undefined`, printWithType('Received', collection, printReceived), ), );