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

Object Properties are ignored in expect when there is a Symbol.iterator #5620

Closed
6 tasks done
mikearnaldi opened this issue Apr 25, 2024 · 6 comments
Closed
6 tasks done
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@mikearnaldi
Copy link
Contributor

Describe the bug

When there is a Symbol.iterator inside an object vitest fails to check for other properties

Reproduction

The following test should fail:

import { describe, expect, it } from "vitest"

describe("Vitest Issue", () => {
  it("compares", () => {
    const a = {
      value: 0,
      [Symbol.iterator]: [0, 1, 2][Symbol.iterator]
    }
    const b = {
      value: 1,
      [Symbol.iterator]: [0, 1, 2][Symbol.iterator]
    }
    expect(a).toStrictEqual(b)
  })
})

System Info

independent from system

Used Package Manager

pnpm

Validations

@mikearnaldi
Copy link
Contributor Author

Note that also the iterator is ignored, the following keeps passing:

import { describe, expect, it } from "vitest"

describe("Vitest Issue", () => {
  it("compares", () => {
    const a = {
      value: 0,
      [Symbol.iterator]: [0, 1, 2, Math.random()][Symbol.iterator]
    }
    const b = {
      value: 1,
      [Symbol.iterator]: [0, 1, 2, Math.random()][Symbol.iterator]
    }
    expect(a).toStrictEqual(b)
  })
})

@sheremet-va
Copy link
Member

Looks like this was fixed in Jest after we migrated the equality check: jestjs/jest#8359

@hi-ogawa
Copy link
Contributor

Note that also the iterator is ignored, the following keeps passing: ...

This one might be some this/bind issue?

> x = { [Symbol.iterator]: ["a", "b"][Symbol.iterator] }
{ [Symbol(Symbol.iterator)]: [Function: values] }
> x[Symbol.iterator]().next()
{ value: undefined, done: true }

> y = { [Symbol.iterator]: () => ["a", "b"][Symbol.iterator]() }
{ [Symbol(Symbol.iterator)]: [Function: [Symbol.iterator]] }
> y[Symbol.iterator]().next()
{ value: 'a', done: false }

@hi-ogawa
Copy link
Contributor

Closed by #5621

@sheremet-va
Copy link
Member

The fix should be in https://github.com/vitest-dev/vitest/releases/tag/v1.5.3

I checked and effect repo is now failing - are these errors expected?

@mikearnaldi
Copy link
Contributor Author

Thank you very much for checking, this issue actually highlighted that we were running in a limbo relying on the fact that only iterable would be compared, we are working on custom matchers to fill the gap Effect-TS/effect#2646

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

No branches or pull requests

3 participants