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

Set support in same members #1583

Merged
merged 9 commits into from
Feb 12, 2024
Merged

Conversation

koddsson
Copy link
Member

@koddsson koddsson commented Jan 26, 2024

Fixes #1468

Add Set support to members/sameMembers. While doing that I want to introduce a iterable assertion that I think could be useful.

@43081j
Copy link
Contributor

43081j commented Jan 27, 2024

should we try support all iterables? may be possible by looking for Symbol.iterator? 🤔

just wondering if we want it to support something which isn't a set or array but is iterable

@keithamus
Copy link
Member

I think supporting iterators generally is a good idea. Otherwise though this is a good step forward.

@koddsson
Copy link
Member Author

should we try support all iterables? may be possible by looking for Symbol.iterator? 🤔

just wondering if we want it to support something which isn't a set or array but is iterable

I think supporting iterators generally is a good idea. Otherwise though this is a good step forward.

Yes! I wanted to change this:

https://github.com/chaijs/chai/pull/1583/files#diff-e3056660026d4431cbb909136ea4290116f5f8be089125a67d6e9ba8f364402dR3145-R3151

to new Assertion(obj, flagMsg, ssfi, true).to.be.an('iterable'); but ran into issues so I'm coming back to it.

@koddsson
Copy link
Member Author

Something that I found is that string has Symbol.iterator so there might be some edge-cases.

lib/chai/core/assertions.js Outdated Show resolved Hide resolved
lib/chai/core/assertions.js Outdated Show resolved Hide resolved
lib/chai/core/assertions.js Outdated Show resolved Hide resolved
@@ -3136,26 +3142,29 @@ function isSubsetOf(_subset, _superset, cmp, contains, ordered) {
* @api public
*/

Assertion.addMethod('members', function (subset, msg) {
Assertion.addMethod('iterable', function(msg) {
Copy link
Member

Choose a reason for hiding this comment

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

👍 this is good

@koddsson
Copy link
Member Author

I was gonna point this PR to #1592 but I guess I can't because it's on a different remote. In any case, I split out the iterable assertion into it's own PR which I think we should merge first and then land this fix.

@koddsson
Copy link
Member Author

I think this is good but might benefit from more tests.

@koddsson koddsson marked this pull request as ready for review February 11, 2024 11:05
@koddsson koddsson requested a review from a team as a code owner February 11, 2024 11:05
@koddsson koddsson merged commit 1ba37b5 into chaijs:main Feb 12, 2024
5 checks passed
@koddsson koddsson deleted the set-support-in-same-members branch February 12, 2024 12:32
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.

assert.sameMembers should work for sets
3 participants