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 doesn't verify key value of type undefined #10029

Closed
erikologic opened this issue May 12, 2020 · 4 comments
Closed

toEqual doesn't verify key value of type undefined #10029

erikologic opened this issue May 12, 2020 · 4 comments

Comments

@erikologic
Copy link
Contributor

#9763 🐛 Bug Report

When verifying an object, if a key is set to undefined it will not be verified.

To Reproduce

it('pass', () => {
    expect({
        key: true
    }).toEqual({
        key: true,
        anotherKey: undefined
    });
});

it('pass too', () => {
    expect({
        key: true,
        anotherKey: undefined
    }).toEqual({
        key: true
    });
});

Expected behavior

IMO it should fail because key anotherKey is not existing in the other object, regardless for it being set to undefined.

Link to repl or repo (highly encouraged)

NA

envinfo

  System:
    OS: macOS 10.15.4
    CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
  Binaries:
    Node: 12.16.0 - ~/.nvm/versions/node/v12.16.0/bin/node
    Yarn: 1.22.4 - ~/.nvm/versions/node/v12.16.0/bin/yarn
    npm: 6.14.5 - ~/.nvm/versions/node/v12.16.0/bin/npm
  npmPackages:
    jest: ^26.0.1 => 26.0.1 
@SimenB
Copy link
Member

SimenB commented May 12, 2020

You should use toStrictEqual for this. Does it need specification in docs?

@erikologic
Copy link
Contributor Author

erikologic commented May 13, 2020

Sorry I missed it totally... :(

Does it need specification in docs?

Do you mean in the .toEqual section?
Maybe that would help

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@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 Mar 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants