Skip to content

[Bug]: objectContaining, arrayContaining, and arrayOf don't compare the contents of Sets, Maps, and other iterables #16508

Description

@paulcyr

Version

30.5.2

Steps to reproduce

  1. Clone https://github.com/EncircleInc/unrestricted
  2. cd bug-reproductions/jest/iterables-in-containing-matchers
  3. npm install
  4. npm test

The reproduction is in https://github.com/EncircleInc/unrestricted/tree/main/bug-reproductions/jest/iterables-in-containing-matchers

Expected behavior

Every test passes. For a Set, a Map, and a custom iterable, the tests check that two instances with different contents don't match: once with toEqual, and once with each of expect.objectContaining, expect.arrayContaining, expect.arrayOf, and expect.objectContaining inside toHaveBeenCalledWith.

Actual behavior

For each type, the toEqual test passes and the other four fail. Inside the containing matchers, a Set, Map, or other iterable that isn't an Array or a typed array matches any other of its kind, no matter what it contains. URLSearchParams and generator objects behave the same way, and so does expect.not.objectContaining, in reverse. An Array, a typed array, or a plain object is compared correctly.

Additional context

#13968 reported this for Map values, and a 2023 comment on #11250 reported it for objectContaining too. #11250 itself was about toMatchObject, which now compares Maps and Sets correctly. The stale bot closed both issues without triage, and the behavior is unchanged on main.

Environment

System:
    OS: Linux 7.0 Ubuntu 24.04.5 LTS 24.04.5 LTS (Noble Numbat)
    CPU: (12) x64 12th Gen Intel(R) Core(TM) i7-1255U
  Binaries:
    Node: 24.17.0 - /run/user/1000/fnm_multishells/1962250_1792181968577/bin/node
    Yarn: 1.22.22 - /home/pcyr/.nvm/versions/node/v24.16.0/bin/yarn
    npm: 11.13.0 - /run/user/1000/fnm_multishells/1962250_1792181968577/bin/npm
    pnpm: 10.34.4 - /home/pcyr/.nvm/versions/node/v24.16.0/bin/pnpm
  npmPackages:
    jest: 30.5.2 => 30.5.2

Activity

  1. added a commit that references this issue on Nov 2, 2026
    a324ccf
  2. added a commit that references this issue on Nov 11, 2026
    999f642
  3. added a commit that references this issue on Nov 12, 2026
    f1e1d1a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions