Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add failing element to satisfyAll and satisfyAny error messages #482

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mattphillips
Copy link
Member

What

Add failing element to satisfyAll and satisfyAny error messages

Why

This will give a clearer error message of why the assertion failed

Notes

Screenshot 2022-08-05 at 13 21 09

Housekeeping

  • Unit tests
  • Documentation is up to date
  • No additional lint warnings
  • Typescript definitions are added/updated where relevant

@codecov
Copy link

codecov bot commented Aug 5, 2022

Codecov Report

Merging #482 (5010b79) into main (877341d) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main      #482   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           71        71           
  Lines          582       584    +2     
  Branches       148       150    +2     
=========================================
+ Hits           582       584    +2     
Impacted Files Coverage Δ
src/matchers/toSatisfyAll.js 100.00% <100.00%> (ø)
src/matchers/toSatisfyAny.js 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@@ -1,23 +1,28 @@
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));
Copy link
Collaborator

@keeganwitt keeganwitt Aug 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why return the first non-matching element? In the case of toSatisfyAny, all elements would fail the predicate during failure scenarios.

@@ -1,23 +1,28 @@
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));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There could be multiple failing elements, right? I'm wondering if it'd be better to print them all instead of just the first one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants