Gathering detailed insights and metrics for jest-sinon
Gathering detailed insights and metrics for jest-sinon
npm install jest-sinon
Typescript
Module System
Node Version
NPM Version
57.6
Supply Chain
55.2
Quality
70.9
Maintenance
100
Vulnerability
97
License
JavaScript (100%)
Total Downloads
2,770,858
Last Day
1,434
Last Week
5,917
Last Month
26,294
Last Year
477,877
15 Stars
74 Commits
4 Forks
1 Watching
5 Branches
2 Contributors
Minified
Minified + Gzipped
Latest Version
1.1.0
Package Id
jest-sinon@1.1.0
Unpacked Size
50.82 kB
Size
5.54 kB
File Count
5
NPM Version
8.11.0
Node Version
16.16.0
Cumulative downloads
Total Downloads
Last day
32.9%
1,434
Compared to previous day
Last week
8.9%
5,917
Compared to previous week
Last month
11%
26,294
Compared to previous month
Last year
-47.4%
477,877
Compared to previous year
1
Jest-Sinon is a collection of assertions for using the mocking library Sinon.js with Jest.
1const bar = () => {}; 2const foo = sinon.spy(); 3 4foo(bar); 5 6// instead of: 7expect(foo.calledWith(bar)).toBeTruthy; 8 9// we can write: 10expect(foo).toHaveBeenCalledWith(bar);
The assertions: toHaveBeenCalledTimes
, toThrow
, toReturnWith
, toHaveBeenCalled
and toHaveBeenCalledWith
clash with the in-built Jest
mocking framework. Jest-Sinon
will try and detect which type of spy is being used and use the correct assertion. You should be able to use both mocking libraries in parallel.
1const foo = sinon.spy(); 2const bar = jest.fn(); 3 4foo(); 5bar(); 6 7expect(foo).toHaveBeenCalled(); // true 8expect(bar).toHaveBeenCalled(); // true
There are a number of reasons why you might want to use Sinon.js
instead of (or as well as) the in-built mocking assertions. Some of the use cases include:
Ultimately, it usually comes down to your own preferences and needs.
With npm:
npm install --save-dev jest-sinon
With yarn:
yarn add -D jest-sinon
Add Jest-Sinon
to your Jest setupFilesAfterEnv
configuration.
1"jest": { 2 "setupFilesAfterEnv": ["jest-sinon"] 3}
1"jest": { 2 "setupTestFrameworkScriptFile": "./testSetup.js" 3}
1// testSetup.js 2 3require('jest-sinon');
Jest-Sinon
adds a number of assertions to help test Sinon.js
Spies, Mocks and Stubs. Below is a list of currently implemented assertions.
.toHaveBeenAlwaysCalledOn(obj)
Also under the alias:
.toBeAlwaysCalledOn()
.toHaveBeenAlwaysCalledWith(args1, arg2, ...)
Also under the alias:
.toBeAlwaysCalledWith()
.toHaveBeenAlwaysCalledWithExactly(args1, arg2, ...)
Also under the alias:
.toBeAlwaysCalledWithExactly()
.toHaveBeenAlwaysCalledWithMatch(arg1, arg2, ...)
Also under the alias:
.toBeAlwaysCalledWithMatch()
.toHaveBeenAlwaysCalledWithNew()
Also under the alias:
.toBeAlwaysCalledWithNew()
.toHaveBeenCalled()
Also under the alias:
.toBeCalled()
.toHaveBeenCalledAfter(anotherSpy)
Also under the alias:
.toBeCalledAfter()
.toHaveBeenCalledBefore(anotherSpy)
Also under the alias:
.toBeCalledBefore()
.toHaveBeenCalledImmediatelyAfter(anotherSpy)
Also under the alias:
.toBeCalledImmediatelyAfter()
.toHaveBeenCalledImmediatelyBefore(anotherSpy)
Also under the alias:
.toBeCalledImmediatelyBefore()
.toHaveBeenCalledOn(obj)
Also under the alias:
.toBeCalledOn()
.toHaveBeenCalledOnce()
Also under the alias:
.toBeCalledOnce()
.toHaveBeenCalledOnceWith(arg1, arg2, ...)
Also under the alias:
.toBeCalledOnceWith()
.toHaveBeenCalledOnceWithExactly(arg1, arg2, ...)
Also under the alias:
.toBeCalledOnceWithExactly()
.toHaveBeenCalledThrice()
Also under the alias:
.toBeCalledThrice()
.toHaveBeenCalledTwice()
Also under the alias:
.toBeCalledTwice()
.toHaveBeenCalledWith(arg1, arg2, ...)
Also under the alias:
.toBeCalledWith()
.toHaveBeenCalledWithExactly(arg1, arg2, ...)
Also under the alias:
.toBeCalledWithExactly()
.toHaveBeenCalledWithMatch(arg1, arg2, ...)
Also under the alias:
.toBeCalledWithMatch()
.toHaveBeenCalledWithNew()
Also under the alias:
.toBeCalledWithNew()
.toHaveCallCount(number)
Also under the alias:
.toHaveBeenCalledTimes()
and.toBeCalledTimes()
.toHaveReturnedWith(obj)
Also under the alias:
.toReturnWith()
,.toHaveReturned()
and.toReturn()
.toHaveAlwaysReturnedWith(obj)
Also under the alias:
.toAlwaysReturnWith()
.toHaveThrown(error?)
Also under the alias:
.toHaveThrownError()
,.toThrow()
, and.toThrowError()
.toHaveAlwaysThrown(error?)
Also under the alias:
.toHaveAlwaysThrownError()
,.toAlwaysThrow()
and.toAlwaysThrowError()
For more information about what these do, you can visit Sinon.js.
Pull requests for new features, bug fixes, and suggestions are welcome!
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
Project has not signed or included provenance with any releases.
Details
Reason
10 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More