-
Notifications
You must be signed in to change notification settings - Fork 39
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
Sets/Maps silently pass #4
Comments
Because Maps & Sets' keys aren't enumerable, one would need to specifically type detect if they are a Map or Set. To do this, you'd need to use You'd then need to create a // if the prototypes dont match, these wont be deep equal. return false early
if (a.prototype !== b.prototype) {
return false;
}
ka = Array.from(a.keys()).sort(); // get the sorted keys for Map a
kb = Array.from(b.keys()).sort(); // get the sorted keys for Map b
if (iterableEqual(ka, kb) === false) { // iterableEqual already exists
return false;
}
// iterate over the first maps keys
for (i = ka.length - 1; i >= 0; i--) {
key = ka[i];
// do a deep equality check on a and b's values of this key
if (!deepEqual(a.get(key), b.get(key), m)) {
return false;
}
} Tests would also need to be added to the test file for a complete PR. |
Hi @keithamus, I will start working on this so we can solve chaijs/chai#394 next. But I think we have to define what will be the behavior when it comes to WeakMaps and WeakSets. These data-structures are not iterable and we cannot get all elements from them. This is what MDN says:
Are we going to use strict ( |
@lucasfcosta hold off on this - sorry. I've actually got a big refactor of deep-eql which should also solve this issue. I'll probably be submitting a PR in about 24 hours. |
Ah, okay, no problem. Let me know if you need any help with it 😃 |
Absolutely not bothering me, it's awesome that you're so keen to work on this all! I'm just bad at being organised at assigning myself to tickets. If you are looking for stuff to work on, a couple of tickets you could definitely close down are: chaijs/chai#407 - Add Proxy support to interfaces, so that unknown property access throws an error. I will finish up with |
Sounds awesome! |
I see this issue is closed, but expect(new Set(['a'])).to.deep.equal(new Set(['b'])) still passes in the current version of Chai :( |
@pigulla this issue is still open. We're working on it 😄 |
Duh. Can't read. My apologies. |
@pigulla deep-eql 1.0 has been released, which fixes this, and will be used in chai 4.0 which is being released soon. Thanks for the issue! |
Chai assert.deepEquals always passes for sets and maps (chaijs/deep-eql#4).
As @hildjj and @rocketraman point out in chaijs/chai#394, deep equality for Maps and Sets doesn't work (because their keys are not exposed like a normal object, which is what we check for).
There's also not any particularly convenient ways to get all of the values out in a succinct way, except maybe the spread operator, but this is only available if transpiling ES6.
With Maps and Sets now a part of Node v4.0, deep-eql should definitely support Maps and Sets.
To implement this, we'd just need to add some extra conditions within around L56 to detect Maps and Sets (and WeakMaps and WeakSets), and call out to functions such as
mapEqual
andsetEqual
.When done, we should PR upstream to chai proper.
The text was updated successfully, but these errors were encountered: