Skip to content

expect.not.objectContaining() does not match documentation #10186

Closed
@ninevra

Description

@ninevra

🐛 Bug Report

The documentation for expect.not.objectContaining() says that it matches any object that is not a superset of the expected object. In fact, it matches any object that contains no entry equal to any entry of the expected object.

The documentation also says that expect.not.objectContaining() is the inverse of expect.objectContaining(). This is not true; for some (expected, received) pairs, neither assertion will match.

To Reproduce

Steps to reproduce the behavior:

import expect from 'expect';

expect({a: 1, b: 3}).toEqual(expect.not.objectContaining({a: 1, b: 2}); // throws

expect({a: 1, b: 3}).toEqual(expect.objectContaining({a: 1, b: 2}); // _also_ throws

In this example, the recieved object ({a: 1, c: 3}) is not a superset of the expected object ({a: 1, b: 2}), so according to the documentation, it should match; however, it does not.

Expected behavior

The behavior should be changed to reflect what the documentation says.

Link to repl or repo (highly encouraged)

repl.it demo.

envinfo

  System:
    OS: Linux 4.15 Ubuntu 18.04.4 LTS (Bionic Beaver)
    CPU: (4) x64 Intel(R) Core(TM) i7-4500U CPU @ 1.80GHz
  Binaries:
    Node: 14.4.0 - ~/.nvm/versions/node/v14.4.0/bin/node
    npm: 6.14.5 - ~/.nvm/versions/node/v14.4.0/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