[new rule] prefer toHaveBeenCalledTimes()
See original GitHub issueThis is a new rule suggestion; it would be nice to enforce toHaveBeenCalledTimes()
over toHaveBeenCalled()
, to ensure functions are only being executed a set amount of times. It’s unlikely making this fixable would be useful, as we would have to make an assumption about the number of times, which could well be incorrect.
I’m happy to make a PR to support this, but don’t have a definite timeframe. I thought it was worth opening the issue for discussion first.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Not getting expected result from .toHaveBeenCalledTimes() in ...
You can't assert if the handleLoginSubmit function is to be called directly. Since it's defined in the private scope of Login SFC.
Read more >JS-0387 · Prefer that unbound methods are called with their ...
toHaveBeenCalledTimes (1)65 expect(execa.run).toHaveBeenCalledWith('yarn add jest') 66}) 67. Avoid referencing unbound methods which may cause unintentional ...
Read more >The Most Important Assertions in Jest, React Testing Library ...
toBeInTheDocument() — these assertions give you the most confidence; Non-UI assertions, such as expect(logBusinessEvent).toHaveBeenCalledTimes(1); Assertions ...
Read more >@homer0/eslint-plugin - npm
This is a basic configuration for Node that extends from plugin:node/recommended . Name: plugin:homer0/node. Browser. This extends the base ...
Read more >Avoid Nesting when you're Testing - Kent C. Dodds
Why using hooks like beforeEach as a mechanism for code reuse leads to ... clickSubmit beforeEach(() => { handleSubmit = jest.fn() user ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
hah, you called it
I think that’s a great idea!
It would also be cool to fix thing like
expect(someMock.mock.calls.length).toBe(3)
intoexpect(someMock).toHaveBeenCalledTimes(3)
, but it might give some false positives?