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 comparison within expect.objectContaining fails #6820

Open
6 tasks done
danny-does-stuff opened this issue Oct 30, 2024 · 2 comments · May be fixed by #6825
Open
6 tasks done

Set comparison within expect.objectContaining fails #6820

danny-does-stuff opened this issue Oct 30, 2024 · 2 comments · May be fixed by #6825
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@danny-does-stuff
Copy link

danny-does-stuff commented Oct 30, 2024

Describe the bug

When comparing Sets within expect.objectContaining, any Set will make the test pass. In other words, the line expect({ set: new Set() }).toEqual(expect.objectContaining({ set: new Set([1]) })); does not cause the test to fail.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-dpdxnv?file=test%2Fbasic.test.ts

System Info

System:
    OS: macOS 15.0.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 34.01 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
  Browsers:
    Brave Browser: 128.1.69.168
    Chrome: 109.0.5414.87
    Edge: 130.0.2849.56
    Safari: 18.0.1
    Safari Technology Preview: 18.0

Used Package Manager

yarn

Validations

@hi-ogawa
Copy link
Contributor

I checked Jest has the same behavior https://stackblitz.com/edit/github-vktwdn?file=basic.test.js, but I don't know for what reason this would make sense. It's probably a bug and should be fixed.

@hi-ogawa hi-ogawa added p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Oct 31, 2024
@hi-ogawa
Copy link
Contributor

It looks like asymmetric matcher's equality doesn't consider iterableEquality, so arrayContaining doesn't work either https://stackblitz.com/edit/vitest-dev-vitest-4n18bx?file=test%2Fbasic.test.ts

import { expect, test } from 'vitest';

test('repro 1', () => {
  expect([new Set()]).toEqual(expect.arrayContaining([new Set([1])]));
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants