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

docs: update toHaveBeenCalledWith to include type of equality check #12222

Merged
merged 5 commits into from
Feb 7, 2022
Merged

docs: update toHaveBeenCalledWith to include type of equality check #12222

merged 5 commits into from
Feb 7, 2022

Conversation

Biki-das
Copy link
Contributor

@Biki-das Biki-das commented Jan 6, 2022

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 | 

@Biki-das
Copy link
Contributor Author

@SimenB ping

docs/ExpectAPI.md Outdated Show resolved Hide resolved
website/versioned_docs/version-25.x/ExpectAPI.md Outdated Show resolved Hide resolved
website/versioned_docs/version-26.x/ExpectAPI.md Outdated Show resolved Hide resolved
@@ -674,7 +674,7 @@ Although the `.toBe` matcher **checks** referential identity, it **reports** a d

Also under the alias: `.toBeCalled()`

Use `.toHaveBeenCalled` to ensure that a mock function got called.
Use `.toHaveBeenCalled` to ensure that a mock function got called.The specific arguments are checked with a `.toEqual` call.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is put in the wrong call

@@ -674,7 +674,7 @@ Although the `.toBe` matcher **checks** referential identity, it **reports** a d

Also under the alias: `.toBeCalled()`

Use `.toHaveBeenCalled` to ensure that a mock function got called.
Use `.toHaveBeenCalled` to ensure that a mock function got called.The specific arguments are checked with a `.toEqual` call.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong call

@@ -674,7 +674,7 @@ Although the `.toBe` matcher **checks** referential identity, it **reports** a d

Also under the alias: `.toBeCalled()`

Use `.toHaveBeenCalled` to ensure that a mock function got called.
Use `.toHaveBeenCalled` to ensure that a mock function got called.The specific arguments are checked with a `.toEqual` call.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong call

@@ -674,7 +674,7 @@ Although the `.toBe` matcher **checks** referential identity, it **reports** a d

Also under the alias: `.toBeCalled()`

Use `.toHaveBeenCalled` to ensure that a mock function got called.
Use `.toHaveBeenCalled` to ensure that a mock function got called.The specific arguments are checked with a `.toEqual` call.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong call

@codecov-commenter
Copy link

codecov-commenter commented Feb 5, 2022

Codecov Report

Merging #12222 (0c604b4) into main (4f4be57) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #12222   +/-   ##
=======================================
  Coverage   67.52%   67.52%           
=======================================
  Files         328      328           
  Lines       17244    17244           
  Branches     5069     5069           
=======================================
  Hits        11644    11644           
  Misses       5567     5567           
  Partials       33       33           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4f4be57...0c604b4. Read the comment docs.

@Biki-das Biki-das requested a review from SimenB February 5, 2022 08:43
@SimenB
Copy link
Member

SimenB commented Feb 5, 2022

@Biki-das you've only merged one of the suggestions and not addressed the comment where I didn't leave a suggestion 🙂

@Biki-das
Copy link
Contributor Author

Biki-das commented Feb 5, 2022

@Biki-das you've only merged one of the suggestions and not addressed the comment where I didn't leave a suggestion 🙂

oh sorry, @SimenB made a new one , see if this works

docs/ExpectAPI.md Outdated Show resolved Hide resolved
@Biki-das Biki-das requested a review from SimenB February 6, 2022 06:05
@Biki-das
Copy link
Contributor Author

Biki-das commented Feb 7, 2022

@SimenB , sorry for this mess up here, i was able to understand the changes and applied them as you said, thanks!

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! 27.5 as well? 🙂

@Biki-das
Copy link
Contributor Author

Biki-das commented Feb 7, 2022

thanks! 27.5 as well? 🙂

sure

@Biki-das Biki-das requested a review from SimenB February 7, 2022 14:51
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect, thanks!

@SimenB SimenB changed the title Doc: update toHaveBeenCalledWith to include type of equality check docs: update toHaveBeenCalledWith to include type of equality check Feb 7, 2022
@SimenB SimenB merged commit 92f3279 into jestjs:main Feb 7, 2022
@Biki-das Biki-das deleted the 3 branch February 7, 2022 14:56
@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.

4 participants