Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toEqual() on Object with undefined values #8588

Closed
jcoyne opened this issue Jun 20, 2019 · 4 comments · Fixed by #13560
Closed

toEqual() on Object with undefined values #8588

jcoyne opened this issue Jun 20, 2019 · 4 comments · Fixed by #13560

Comments

@jcoyne
Copy link

jcoyne commented Jun 20, 2019

🐛 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
@jeysal
Copy link
Contributor

jeysal commented Jun 20, 2019

Use toStrictEqual for that. We'd like it to be the default, but that'd be a big breaking change

@jeysal jeysal closed this as completed Jun 20, 2019
@jcoyne
Copy link
Author

jcoyne commented Jun 20, 2019

Thanks for the advice. I totally missed that in the docs. I wonder if this section should be updated to point people there: https://jestjs.io/docs/en/using-matchers#common-matchers

@jeysal
Copy link
Contributor

jeysal commented Jun 20, 2019

Yes, I think it would be a good idea to suggest toStrictEqual in there. Do you want to send a PR? :)

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants