-
-
Notifications
You must be signed in to change notification settings - Fork 697
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
Keys for maps and sets #633
Conversation
@@ -1142,6 +1145,9 @@ module.exports = function (chai, _) { | |||
* expect({ foo: 1, bar: 2 }).to.have.all.keys({'bar': 6, 'foo': 7}); | |||
* expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys(['bar', 'foo']); | |||
* expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys({'bar': 6}); | |||
* expect(new Map([[{objKey: 'value'}, 'value'], [1, 2]])).to.contain.key({objKey: 'value'}); | |||
* expect(new Map([['firstKey', 'firstValue'], [1, 2]])).to.contain.all.keys('firstKey', 1); | |||
* expect(new Set([['foo', 'bar'], ['example', 1]])).to.have.any.keys('foo'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to have an example of passing multiple objects as keys here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it would be good!
Totally forgot it, thanks for pointing this
Only a couple of minor points above. Otherwise this looks awesome @lucasfcosta. Great work, as usual 😄 |
Thanks, @keithamus! Well, I'm aware expect(new Map([[{objKey: 'value'}, 'value'], [1, 2]])).to.contain.key([{objKey: 'value'}]); This will fail, because although the object used as key on the map is depply equal to the one passed to the |
@lucasfcosta sure, I expected you to say as much - I should have elaborated more in my original comment, but got a little side tracked with other things. Deep equality is going to be sometimes desirable within Maps, but sometimes referential equality will be desirable. If we start with using referential equality, we can always move to deep equality later - by adding the |
Ah, I understand now and I totally agree, it really seems to be the right step. I haven't thought about it before. Thanks for the explanation, I'll make sure to update this PR with the changes we talked about ASAP 😃 |
We can tackle the deep flag in another PR, to keep this one simple 😄 |
c675734
to
22a8531
Compare
22a8531
to
c654360
Compare
This one is done! 🎉 And thanks again for your support! |
@lucasfcosta awesome 😄 |
Fantastic work as usual @lucasfcosta. Feel free to make a PR adding support for deep Map/Set keys 😄 |
Thanks @keithamus, I'll certainly do it 😄 |
close #632 ? |
Hello everyone, this PR aims to solve #632.
Here's a summary of the changes I made:
.some()
instead of.filter()
when checking forany
keys. There is no need to calculate the full size of intersections (intersection > 0
), if we have one it's already bigger than0
therefore we don't need to iterate through everything.mixedArgs
message becausekeys
assertion now accepts objects as keys (as I've said on Add assertions for ES6 Maps and Sets #632)._.eql(expectedKey, actualKey)
.assert
interface had nokeys
related methods, so I added every possible combination (any/all/contains/have - Please notice that some of these combinations have the same meaning, as explained on thekeys
method description, so I added only the ones with different effects)PS.: When creating these tests I've had to use
if (Maps !== undefined)
andif (Sets !== undefined)
because apparently PhantomJS 1.9 uses an engine that hasn't implemented these specs yet.Feel free to point possible mistakes and give feedback or new ideas.
Thanks everyone