Skip to content

toEqual() on Object with undefined valuesΒ #8588

@jcoyne

Description

@jcoyne

πŸ› Bug Report

When calling toEqual on an object, where one of the values is undefined does not compare that key.

To Reproduce

This assertion fails:

    expect({foo: 1, bar: undefined}).not.toEqual({foo: 1})
  ● toEqual β€Ί should compare objects

    expect(received).not.toEqual(expected)

    Expected value to not equal:
      {"foo": 1}
    Received:
      {"bar": undefined, "foo": 1}

      1 | describe('toEqual', () => {
      2 |   it('should compare objects', () => {
    > 3 |     expect({foo: 1, bar: undefined}).not.toEqual({foo: 1});
      4 |   });
      5 | });

Expected behavior

That should pass.

Link to repl or repo (highly encouraged)

https://repl.it/repls/KeenSnappyCodewarrior

Run npx envinfo --preset jest

Paste the results here:

$ npx envinfo --preset jest
npx: installed 1 in 1.377s

  System:
    OS: macOS 10.14.5
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  Binaries:
    Node: 11.7.0 - /usr/local/homebrew/bin/node
    Yarn: 1.13.0 - /usr/local/homebrew/bin/yarn
    npm: 6.9.0 - /usr/local/homebrew/bin/npm
  npmPackages:
    jest: ^24.7.1 => 24.7.1

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