Skip to content

objectContaining not matching valid subset per docs #11126

Closed as not planned
Closed as not planned
@cdaringe

Description

@cdaringe

🐛 Bug Report

Per the docs https://jestjs.io/docs/en/expect#expectobjectcontainingobject, the following minimal assertion is expected to pass

describe("objectContaining", () => {
  it("should work", () => {
    const headers = new Headers({});
    headers.set("weee", "weee");
    expect({
      a: "a",
      headers,
      b: {
        c: new Map(),
        d: "awfiotnaf",
      },
    }).toEqual(
      expect.objectContaining({
        b: {
          d: expect.any(String),
        },
      })
    );
  });
});

.toEqual seems suspicious, but peers in the community have asserted that because of the subset language, the above should still. take.

To Reproduce

pnpx jest

Link to repl or repo (highly encouraged)

https://github.com/cdaringe/jest-object-containing

envinfo


  System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
  Binaries:
    Node: 14.4.0 - /usr/local/bin/node
    Yarn: 1.22.5 - ~/.yarn/bin/yarn
    npm: 6.14.4 - /usr/local/bin/npm


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