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

Validate if spy or mock was passed when expected #203

Merged
merged 2 commits into from
Oct 11, 2021

Conversation

atsikov
Copy link
Contributor

@atsikov atsikov commented Mar 4, 2019

What

Add error to toHaveBeenCalledBefore and toHaveBeenCalledAfter matchers in case passed params are not instances of jest.Mock

Why

Jest has similar errors when non spy or mock is passed to toHaveBeenCalled or other mock-related matchers.

  • Unit tests
  • No additional lint warnings

@codecov-io
Copy link

codecov-io commented Mar 4, 2019

Codecov Report

Merging #203 (4a3aff6) into main (449905f) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #203   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          125       125           
  Lines          774       792   +18     
  Branches       115       124    +9     
=========================================
+ Hits           774       792   +18     
Impacted Files Coverage Δ
src/matchers/toHaveBeenCalledAfter/index.js 100.00% <100.00%> (ø)
src/matchers/toHaveBeenCalledBefore/index.js 100.00% <100.00%> (ø)
src/utils/index.js 100.00% <100.00%> (ø)

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 449905f...4a3aff6. Read the comment docs.

@atsikov atsikov force-pushed the check-jest-mock-params branch from df9a436 to 13ee080 Compare March 6, 2019 10:59
Copy link
Contributor

@benjaminkay93 benjaminkay93 left a comment

Choose a reason for hiding this comment

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

This is a really great PR, and going to be really useful as more mocking matchers are added 🎉.

Ive stuck a comment on one little bit where I couldn't read the logic easily which could lead to it being hard to maintain in the future.

Also just worrying abit about how clear we are being to our users on the error message outputted :)

Hope to hear from you soon about how you feel about these comments 😺

src/utils/index.js Outdated Show resolved Hide resolved
src/matchers/toHaveBeenCalledBefore/index.js Outdated Show resolved Hide resolved
src/matchers/toHaveBeenCalledAfter/index.js Outdated Show resolved Hide resolved
src/matchers/toHaveBeenCalledBefore/index.js Show resolved Hide resolved
@atsikov atsikov force-pushed the check-jest-mock-params branch from 13ee080 to 4aa02cb Compare March 11, 2019 09:46
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!

@SimenB SimenB merged commit d5dd8f1 into jest-community:main Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants