Skip to content

Order-sensitive diff on expect.arrayContaining failure #8913

Closed

Description

@btomaj

Describe the bug

Diff from failed expect.arrayContaining([...]) assertion is incorrectly order sensitive.

I expect that the diff should be order-agnostic, and correctly identify all matching elements.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-92aubqtb

Used Package Manager

npm

Validations

Activity

  1. added theissue type on Nov 3, 2025
  2. btomaj commented on Nov 4, 2025

    @btomaj
    Author

    I'm working on a fix for this.

  3. btomaj commented on Nov 5, 2025

    @btomaj
    Author

    I'm facing a design choice. To produce an order-agnostic diff, I either:

    • Add a symmetricOrder(other: Array<T>): ArrayContaining<T> method to ArrayContaining, and make ArrayContaining responsible for producing an array in the order of the actual array, or
    • Having created a getArrayContainingDifference function, similar to getObjectsDifference, in the diff package, I make getArrayContainingDifference responsible for producing an order-agnostic diff in full (with some coupling to ArrayContaining).

    I need input from a maintainer.

  4. ghostd commented on Nov 5, 2025

    @ghostd

    @btomaj interesting question, i just commented another issue which could be related

  5. changed the title [-]Incorrect diff on arrayContaining failure[/-] [+]Order-sensitive diff on arrayContaining failure[/+] on Nov 5, 2025
  6. changed the title [-]Order-sensitive diff on arrayContaining failure[/-] [+]Order-sensitive diff on expect.arrayContaining failure[/+] on Nov 5, 2025
  7. btomaj commented on Nov 9, 2025

    @btomaj
    Author

    I have come to realise that I can fix this diffing issue only at the top level, and that any nested ArrayContaining will still diff incorrectly. The diff engine relies on the pretty-print engine to handle nested objects and arrays, but the fix needs to live in the diff engine because only the diff engine has awareness of both the expected and actual arrays. Fixing this issue at any level of nesting requires that the recursion that handles nesting moves out of the pretty-print engine, and into the diff engine, but that’s a very big change that I imagine requires longer discussion.

    Looking for input.

  8. moved this to P2 - 2 in Team Boardon Apr 7, 2026
  9. added
    p2-to-be-discussed
    on Apr 7, 2026
  10. btomaj commented on Jul 18, 2026

    @btomaj
    Author

    @sheremet-va was this discussed? Was there an outcome?

  11. moved this from P2 - 2 to Approved in Team Boardon Aug 28, 2026
  12. sheremet-va commented on Aug 28, 2026

    @sheremet-va
    Member

    We think it expect.arrayContaining diff should not be order sensitive

  13. btomaj commented on Sep 8, 2026

    @btomaj
    Author

    @sheremet-va thank you for confirming. Is my PR on the right track?

  14. added
    p3-minor-bug
    and removed
    p2-to-be-discussed
    on Oct 9, 2026
  15. locked and limited conversation to collaborators on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bug

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions