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

fix: vitest custom tester with toMatchObject #2688

Conversation

sukovanej
Copy link
Contributor

Currently, the usage of the custom tester breaks expect(...).toMatchObject(...). Failing example:

    expect({ a: 1, b: 2 }).toMatchObject({ a: 1 })

The reason is that toMatchObject in vitest is implemented as an equality check with subsetEquality as a last custom tester. Our custom tester currently doesn't have any skip logic to allow continuation of the testers pipeline it's part of. Another problematic thing is that the toMatchObject is not commutative, and it uses equality which is commutative. Therefore in equal impl of Option, Either, ... the matching breaks when the arguments are passed to Equal.equals in an opposite order.

Copy link

changeset-bot bot commented May 2, 2024

🦋 Changeset detected

Latest commit: 9db3161

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 24 packages
Name Type
effect Patch
@effect/vitest Patch
@effect/cli Patch
@effect/experimental Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/platform Patch
@effect/printer-ansi Patch
@effect/printer Patch
@effect/rpc-http Patch
@effect/rpc Patch
@effect/schema Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/sql Patch
@effect/typeclass Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@sukovanej sukovanej force-pushed the fix/vitest-equality-tester-to-match-object branch from 1a623ef to e833052 Compare May 2, 2024 21:16
@mikearnaldi
Copy link
Member

Not sure why but this makes some tests fail, also not sure about the early escape of Equal

@sukovanej sukovanej requested a review from gcanti as a code owner May 3, 2024 17:14
@sukovanej sukovanej force-pushed the fix/vitest-equality-tester-to-match-object branch 2 times, most recently from 2c44ed3 to 161c8cb Compare May 3, 2024 17:15
@sukovanej
Copy link
Contributor Author

sukovanej commented May 3, 2024

Not sure why but this makes some tests fail, also not sure about the early escape of Equal

It really looks like the assertion in the failing test is incorrect. I'm not sure why it'd occur just now tho.

@sukovanej sukovanej force-pushed the fix/vitest-equality-tester-to-match-object branch from 161c8cb to 9db3161 Compare May 3, 2024 19:50
@sukovanej
Copy link
Contributor Author

also not sure about the early escape of Equal

Me neither, but I'm not aware of any better solution. Also, I have another example that will fail even with the proposed change.

  it("Data.struct", () => {
    const alice = Data.struct({ name: "Alice", age: 30 })

    expect(alice).toMatchObject(Data.struct({ name: "Alice" }))
  })

@mikearnaldi
Copy link
Member

also not sure about the early escape of Equal

Me neither, but I'm not aware of any better solution. Also, I have another example that will fail even with the proposed change.

  it("Data.struct", () => {
    const alice = Data.struct({ name: "Alice", age: 30 })

    expect(alice).toMatchObject(Data.struct({ name: "Alice" }))
  })

Is that because of the symbols?

@sukovanej
Copy link
Contributor Author

also not sure about the early escape of Equal

Me neither, but I'm not aware of any better solution. Also, I have another example that will fail even with the proposed change.

  it("Data.struct", () => {
    const alice = Data.struct({ name: "Alice", age: 30 })

    expect(alice).toMatchObject(Data.struct({ name: "Alice" }))
  })

Is that because of the symbols?

It's because of hash check in compareBoth.

@mikearnaldi
Copy link
Member

mikearnaldi commented May 4, 2024 via email

@sukovanej
Copy link
Contributor Author

I debugged that locally, the circuit shorts in here. Even if the hash check wasn't there it would return false on comparison inside of the equal of the StructuralPrototype.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants