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

doc: update toHaveBeenCalledWith to include type of equality check #11026

Closed
wants to merge 1 commit into from

Conversation

byrne-greg
Copy link

Summary

The documentation for .toHaveBeenCalledWith doesn't state the type of equality check performed on the argument.

This means that anyone expecting the object argument used in the mock function .toStrictEqual the passed argument will be confused as the call is actually .toEqual and doesn't compare object classes.

 FAIL  ./index.test.js
  ✕ toHaveBeenCalledWith doesn't compare objects strictly (22 ms)

  ● toHaveBeenCalledWith doesn't compare objects strictly

    expect(received).toStrictEqual(expected) // deep equality

    - Expected  - 1
    + Received  + 1

    - Object {
    + AClass {
        "id": 1,
        "name": "Parent A",
      }

       9 |   expect(utils.f2).toHaveBeenCalledWith(data) // passes
      10 |   expect(utils.f2.mock.calls[0][0]).toEqual(data) // passes
    > 11 |   expect(utils.f2.mock.calls[0][0]).toStrictEqual(data) // fails  
         |                                     ^
      12 | })
      13 | 

See https://github.com/byrne-greg/jest-toHaveBeenCalledWith-equal-example/blob/main/index.test.js as an example

Test plan

@SimenB
Copy link
Member

SimenB commented Feb 7, 2022

Landed via #12222 I believe, sorry I missed this PR!

@SimenB SimenB closed this Feb 7, 2022
@byrne-greg byrne-greg deleted the doc/update-matcher branch February 8, 2022 07:04
@github-actions
Copy link

This pull request 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 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants