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

Assertion Enhancement: toBeCalled(x) #1689

Closed
kentcdodds opened this issue Sep 14, 2016 · 2 comments
Closed

Assertion Enhancement: toBeCalled(x) #1689

kentcdodds opened this issue Sep 14, 2016 · 2 comments

Comments

@kentcdodds
Copy link
Contributor

I'd like to request that we either add toBeCalledOnce() or toBeCalled(x) where x represents the number of times the mock function was called.

There is a subtle but significant difference between these two assertions:

expect(foo).toBeCalled()
expect(foo.mock.calls.length).toBe(1)

The difference is that the second asserts that it was called only one time. No more, no less. The first only asserts that it was called, not that it was only called one time.

@aaronabramov
Copy link
Contributor

actually.. we already have expect(jest.fn()).toHaveBeenCalledTimes(x)
but unfortunately it's not documented :)
sorry.. we're still cleaning things up in our documentation

This was referenced Nov 17, 2020
@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 May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants