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

Alter the plugin to use stricter "to satisfy" semantics. #37

Merged
merged 10 commits into from Aug 8, 2020

Conversation

alexjeffburke
Copy link
Member

The behaviour of allowing a set to compare against an array as part
of "to satisfy" has shown itself to be surprising - exclude this
behaviour from "to satisfy" and rename it as a separate assertion
which still allows an array-like on the RHS.

Perhaps more importantly a non-exhaustive satisfy passed with a
subset on the RHS. This is another very surprising behaviour given
arrays in core enforce an equal length. Switch to enforcing the Set
being equal size by default.

The behaviour of allowing a set to compare against an array as part
of "to satisfy" has shown itself to be surprising - exclude this
behaviour from "to satisfy" and rename it as a separate assertion
which still allows an array-like on the RHS.

Perhaps more importantly a non-exhaustive satisfy passed with a
subset on the RHS. This is another very surprising behaviour given
arrays in core enforce an equal length. Switch to enforcing the Set
being equal size by default.
Copy link
Member

@papandreou papandreou left a comment

Choose a reason for hiding this comment

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

Ah, nice!

I thought I volunteered to do this, but luckily I didn't have a chance to work on it yet :)

Remember to fix the documentation tests too.

test/unexpected-set.js Show resolved Hide resolved
@alexjeffburke
Copy link
Member Author

Ah, nice!

I thought I volunteered to do this, but luckily I didn't have a chance to work on it yet :)

Remember to fix the documentation tests too.

Oh I'm sorry if I took your thunder - just thought I'd provide a head start since I had a few spare mins the other day.

@papandreou
Copy link
Member

Oh I'm sorry if I took your thunder

No worries, I hadn't started :)

@coveralls
Copy link

coveralls commented Jun 28, 2020

Coverage Status

Coverage increased (+3.7%) to 96.809% when pulling 6f74783 on stricter-satisfy-semantics into f0473c6 on master.

lib/unexpected-set.js Outdated Show resolved Hide resolved
@alexjeffburke
Copy link
Member Author

Around the question of whether the members of a set should be allowed to have things missing - the documentation examples might be a good guide.

The thing that gave me pause for thought was the following case:

expected Set([ 1, 2, 3 ]) to satisfy
Set([
  1,
  expect.it('to be less than or equal to', 1),
  expect.it('to be greater than', 10)
])

Set([
  1,
  2, // should be removed
  3 // should be removed
  // missing: should be greater than 10
])

The RHS specifies three items, but two of those things are satisfied by the same element on the LHS. I guess what this pokes at is what "exhaustively" really means when applied to Set comparisons.

@papandreou
Copy link
Member

I still think that <Set> to satisfy <Set> and <Set> to [exhaustively] satisfy <Set> should mean the same thing at the first level. The current semantics are just too surprising.

Copy link
Member

@papandreou papandreou left a comment

Choose a reason for hiding this comment

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

LGTM 😌

lib/unexpected-set.js Outdated Show resolved Hide resolved
@alexjeffburke
Copy link
Member Author

@papandreou turns out there was already a (seemingly) undocumented "to have items satisfying" assertion in the plugin - I've adjusted this to the new semantics and added documentation. Please have another look :)

Copy link
Member

@papandreou papandreou left a comment

Choose a reason for hiding this comment

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

Looks good, just some objections against the to have items satisfying implementation.

documentation/assertions/Set/to-have-items-satisfying.md Outdated Show resolved Hide resolved
lib/unexpected-set.js Show resolved Hide resolved
lib/unexpected-set.js Outdated Show resolved Hide resolved
Copy link
Member

@papandreou papandreou left a comment

Choose a reason for hiding this comment

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

LGTM ⚡

documentation/assertions/Set/to-have-items-satisfying.md Outdated Show resolved Hide resolved
test/unexpected-set.js Outdated Show resolved Hide resolved
alexjeffburke and others added 2 commits August 8, 2020 16:53
Co-authored-by: Andreas Lind <andreaslindpetersen@gmail.com>
Co-authored-by: Andreas Lind <andreaslindpetersen@gmail.com>
@alexjeffburke alexjeffburke merged commit 37475fb into master Aug 8, 2020
@alexjeffburke alexjeffburke deleted the stricter-satisfy-semantics branch August 8, 2020 15:23
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

3 participants