diff --git a/src/matchers/toSatisfyAll.js b/src/matchers/toSatisfyAll.js index a2209151..6a5366ef 100644 --- a/src/matchers/toSatisfyAll.js +++ b/src/matchers/toSatisfyAll.js @@ -1,13 +1,18 @@ export function toSatisfyAll(actual, expected) { const { printReceived, printExpected, matcherHint } = this.utils; + const pass = actual.every(expected); + const failingElement = pass ? actual.find(expected) : actual.find(a => !expected(a)); + const passMessage = matcherHint('.not.toSatisfyAll') + '\n\n' + 'Expected array to not satisfy predicate for all values:\n' + ` ${printExpected(expected)}\n` + 'Received:\n' + - ` ${printReceived(actual)}`; + ` ${printReceived(actual)}\n` + + 'Failed on:\n' + + ` ${printReceived(failingElement)}`; const failMessage = matcherHint('.toSatisfyAll') + @@ -15,9 +20,9 @@ export function toSatisfyAll(actual, expected) { 'Expected array to satisfy predicate for all values:\n' + ` ${printExpected(expected)}\n` + 'Received:\n' + - ` ${printReceived(actual)}`; - - const pass = actual.every(expected); + ` ${printReceived(actual)}\n` + + 'Failed on:\n' + + ` ${printReceived(failingElement)}`; return { pass, message: () => (pass ? passMessage : failMessage) }; } diff --git a/src/matchers/toSatisfyAny.js b/src/matchers/toSatisfyAny.js index 665b36fc..302aa238 100644 --- a/src/matchers/toSatisfyAny.js +++ b/src/matchers/toSatisfyAny.js @@ -1,13 +1,18 @@ export function toSatisfyAny(actual, expected) { const { printReceived, printExpected, matcherHint } = this.utils; + const pass = actual.some(expected); + const failingElement = pass ? actual.find(expected) : actual.find(a => !expected(a)); + const passMessage = matcherHint('.not.toSatisfyAny') + '\n\n' + 'Expected array to not satisfy predicate for any value:\n' + ` ${printExpected(expected)}\n` + 'Received:\n' + - ` ${printReceived(actual)}`; + ` ${printReceived(actual)}\n` + + 'Failed on:\n' + + ` ${printReceived(failingElement)}`; const failMessage = matcherHint('.toSatisfyAny') + @@ -15,9 +20,9 @@ export function toSatisfyAny(actual, expected) { 'Expected array to satisfy predicate for any values:\n' + ` ${printExpected(expected)}\n` + 'Received:\n' + - ` ${printReceived(actual)}`; - - const pass = actual.some(expected); + ` ${printReceived(actual)}\n` + + 'Failed on:\n' + + ` ${printReceived(failingElement)}`; return { pass, message: () => (pass ? passMessage : failMessage) }; } diff --git a/test/matchers/__snapshots__/toSatisfyAll.test.js.snap b/test/matchers/__snapshots__/toSatisfyAll.test.js.snap index 0dfa54ed..7ee4996c 100644 --- a/test/matchers/__snapshots__/toSatisfyAll.test.js.snap +++ b/test/matchers/__snapshots__/toSatisfyAll.test.js.snap @@ -6,7 +6,9 @@ exports[`.not.toSatisfyAll fails when all values satisfy predicate 1`] = ` Expected array to not satisfy predicate for all values: [Function isOdd] Received: - [1, 3, 5, 7]" + [1, 3, 5, 7] +Failed on: + 1" `; exports[`.toSatisfyAll fails when any value does not satisfy the predicate 1`] = ` @@ -15,5 +17,7 @@ exports[`.toSatisfyAll fails when any value does not satisfy the predicate 1`] = Expected array to satisfy predicate for all values: [Function isOdd] Received: - [1, 3, 4, 5]" + [1, 3, 4, 5] +Failed on: + 4" `; diff --git a/test/matchers/__snapshots__/toSatisfyAny.test.js.snap b/test/matchers/__snapshots__/toSatisfyAny.test.js.snap index d2abc494..be70e7b9 100644 --- a/test/matchers/__snapshots__/toSatisfyAny.test.js.snap +++ b/test/matchers/__snapshots__/toSatisfyAny.test.js.snap @@ -6,7 +6,9 @@ exports[`.not.toSatisfyAll fails when any value satisfies predicate 1`] = ` Expected array to not satisfy predicate for any value: [Function isOdd] Received: - [2, 3, 6, 8]" + [2, 3, 6, 8] +Failed on: + 3" `; exports[`.toSatisfyAny fails when no value satisfies the predicate 1`] = ` @@ -15,5 +17,7 @@ exports[`.toSatisfyAny fails when no value satisfies the predicate 1`] = ` Expected array to satisfy predicate for any values: [Function isOdd] Received: - [2, 4, 6, 8]" + [2, 4, 6, 8] +Failed on: + 2" `;