Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
eslint-plugin-calledwith-calledtimes
Advanced tools
suggest using toHaveBeenCalledTimes when using toHaveBeenCalledWith
This plugin checks your test matchers (jasmine, jest, vitest) when
toHaveBeenCalledWith
is used, and let's you know you should pair it with toHaveBeenCalledTimes
.
The purpose of this is to ensure that not only our function is called with arguments, but it is called the exact amount of times that we expected.
toHaveBeenCalledWith
checks that a function was called with specific argumentstoHaveBeenCalledTimes
checks that a function was called an expected amount of timesexpect(consoleSpy).toHaveBeenCalledWith('sending');
expect(consoleSpy).toHaveBeenCalledWith('cancelling');
This doesn't check that the function was called the amount of times we expected it to be called.
expect(consoleSpy).toHaveBeenCalledWith("sending");
expect(consoleSpy).toHaveBeenCalledWith("cancelling");
+ expect(consoleSpy).toHaveBeenCalledTimes(2);
Now if consoleSpy
happens to accidentally get called more than we expected, it will error.
This gives us confidence that our code works exactly as expected.
toHaveBeenNthCalledWith
checks that a function was called with specific arguments on the nth time the function was calledtoHaveBeenCalledTimes
checks that a function was called an expected amount of timesexpect(consoleSpy).toHaveBeenNthCalledWith(1, 'sending');
expect(consoleSpy).toHaveBeenNthCalledWith(2, 'cancelling');
expect(consoleSpy).toHaveBeenCalledTimes(2);
[!NOTE]
Currently, this has only been tested withjest
but it should work with other test frameworks likejasmine
andvitest
. Please let me know if it works with these.
You'll first need to install ESLint:
npm i eslint --save-dev
Next, install eslint-plugin-calledwith-calledtimes
:
npm install eslint-plugin-calledwith-calledtimes --save-dev
Add calledwith-calledtimes
to the plugins section of your .eslintrc
configuration file. You
can omit the eslint-plugin-
prefix:
{
"plugins": ["calledwith-calledtimes"]
}
This only needs to run against
Then configure the rules you want to use under the rules section.
{
"rules": {
"calledwith-calledtimes/jest": "warn"
}
}
TODO: Run eslint-doc-generator to generate the configs list (or delete this section if no configs are offered).
🔧 Automatically fixable by the --fix
CLI option.
Name | Description | 🔧 |
---|---|---|
jest | Ensures that using test matcher toHaveBeenCalledWith is followed by toHaveBeenCalledTimes | 🔧 |
FAQs
suggest using toHaveBeenCalledTimes when using toHaveBeenCalledWith
The npm package eslint-plugin-calledwith-calledtimes receives a total of 3 weekly downloads. As such, eslint-plugin-calledwith-calledtimes popularity was classified as not popular.
We found that eslint-plugin-calledwith-calledtimes demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.