-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
toEqual
not symmetric for Set
#7975
Comments
The logic doing the check for |
Keep digging! An inconsistent result is a problem. To decide on a solution, we need to think what a deep-equality comparison means for instances in sets (or tuples with instance keys in maps). describe('Set', () => {
test('primitives', () => {
const set = new Set([false, true, false]);
expect(set.size).toBe(2);
});
test('primitives versus instances', () => {
const set = new Set([
false,
true,
false,
new Boolean(false),
new Boolean(true),
new Boolean(false)
]);
expect(set.size).toBe(5);
expect(set).toMatchSnapshot();
});
});
|
Indeed the Do we need to consider that Today, we do consider that But clearly the real issue above all is the symmetry. I would have expected to have a symmetrical |
The
to call either
Here are a few quotes from https://leanpub.com/understandinges6/read#leanpub-auto-sets-and-maps
|
Thanks a lot for the entry points for the equality of two Set. Here are some of the quick remarks I have about the code section. Remark 1 It seems that (1) https://github.com/facebook/jest/blob/master/packages/expect/src/utils.ts#L159-L178 is doing the same as (2) https://github.com/facebook/jest/blob/master/packages/expect/src/utils.ts#L212-L223. Returning false at line 178 should be ok. Remark 2 I think we could add a Analysis In the case of I went through the code with logs everywhere to track what was going on.
The real problem is that we check that all values within a are within b but not the contrary.
A simple fix would be to do the symmetric check for b. |
The underlying problem is that Possible fixes I can come with:
|
That's a great find. I have been playing around with First of all, there is one more bug with this tester. The code below throws const a = new Set();
const b = new Set();
a.add(a);
b.add(b);
expect(a).toEqual(b); @pedrottimark is there reason why |
For future reference: #8281 introduces Map/Set special handling because of this problem |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days. |
This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🐛 Bug Report
toEqual
is not symmetric forSet
:To Reproduce
Steps to reproduce the behavior: try the code snippet above.
Expected behavior
I would have expected to have the same result for
expect(s1).not.toEqual(s2)
andexpect(s2).not.toEqual(s1)
.Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: