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

.members should work with ES6 Sets/WeakSets #1096

Closed
rijnhard opened this issue Nov 30, 2017 · 4 comments
Closed

.members should work with ES6 Sets/WeakSets #1096

rijnhard opened this issue Nov 30, 2017 · 4 comments

Comments

@rijnhard
Copy link

rijnhard commented Nov 30, 2017

Similar to #632

An ES6 Set should work with the members function just like an array.

Pass conditions

expect(new Set([1, 2, 3])).to.have.members([2, 1, 3]);
expect(new Set([{a: 1}])).to.have.deep.members([{a: 1}]);
expect(new Set([1, 2, 3])).to.have.ordered.members([1, 2, 3]);

// it may also be a good idea to flip it and allow sets to be used just as arrays would
expect([1, 2, 3]).to.have.members(new Set([2, 1, 3]));
expect([{a: 1}]).to.have.deep.members(new Set([{a: 1}]));
expect([1, 2, 3]).to.have.ordered.members(new Set([1, 2, 3]));

Fail conditions should eb the exact same as that of arrays.

@rijnhard
Copy link
Author

For WeakSets it's the same.

const x = { t: 1 },
    y = { t: 2 },
    z = { t: 3 };

expect(new WeakSet([x, y, z])).to.have.members([x, y, z]);

@rijnhard
Copy link
Author

And just for anybody else that gets here the workaround is using Array.from

expect(Array.from(new Set([1, 2, 3]))).to.have.members([2, 1, 3]);

@meeber
Copy link
Contributor

meeber commented Nov 30, 2017

@rijnhard It makes sense to me that .members should support both Maps and Sets. In the meantime, it's worth noting though that .keys already provides some of the functionality you're looking for:

expect(new Set([1, 2, 3])).to.have.keys([2, 1, 3]);
expect(new Set([{a: 1}])).to.have.deep.keys([{a: 1}]);

@keithamus
Copy link
Member

Hey @rijnhard thanks for the issue.

This would be awesome! We've added this to our Roadmap https://github.com/chaijs/chai/projects/2! We'll be releasing chai 5 soon, but for now I'll close this issue because it is tracked on our roadmap.

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

No branches or pull requests

3 participants