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
spyOn functionality #1749
Comments
This is tracked as part of #1679. |
Maybe incorrect about this but isn't the |
See also #2534. |
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. |
I am trying to figure out how to best approach following use case in jest.
I don't want to mock function, just spy on it and let original implementation do the work. Lets say I want to track how many times query was called on postgres driver. Following approach works:
Issue is that I also have to assign original implementation at the end of the test so it does not affect others in same file. So its simple to break test isolation if one person forget such clean up.
I also noticed that jasmine have spyOn which seems to work in jest as well (but not documented), which is pretty elegant, so same thing can be achieved by:
And jasmine claim to remove the spy after the test automatically, which is awesome.
But not sure if thats something that will become official part of jest? Issue is that jasmine spies have different interface than mocks in jest. So I think best would be just to extend mock functionality so it can be easily used for spying using
spyOn
or something similar.Any feedback welcomed.
The text was updated successfully, but these errors were encountered: