Gathering detailed insights and metrics for jest-sandbox
Gathering detailed insights and metrics for jest-sandbox
Gathering detailed insights and metrics for jest-sandbox
Gathering detailed insights and metrics for jest-sandbox
@jdes/jest-sandbox
A Sinon's sandbox like for Jest
sandworm-jest
Security Snapshot Testing Inside Your Jest Test Suite 🪱
@4c/selenium-sandbox
easily mock a web application accessed through selenium. Contains also an environment for integrating with jest.
@yasshi2525/jest-environment-akashic
Sandbox of akashic environment for unit test with jest
npm install jest-sandbox
Typescript
Module System
Node Version
NPM Version
82.4
Supply Chain
98.4
Quality
81.1
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
16 Stars
28 Commits
1 Forks
5 Watchers
283 Branches
6 Contributors
Updated on Feb 07, 2022
Minified
Minified + Gzipped
Latest Version
1.1.2
Package Id
jest-sandbox@1.1.2
Size
4.42 kB
NPM Version
5.6.0
Node Version
8.9.4
Published on
Feb 19, 2018
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Track jest spies and stubs easily.
The one feature I really missed when switching from sinon.js to jest spies and mocks was sandboxes. They allow you to create as many spies and stubs as you want without having to track them all and clear them manually.
1import createSandbox from 'jest-sandbox'; 2 3import cow from './moo.js'; 4 5describe('A cow ????', () => { 6 const sandbox = createSandbox(); 7 8 // Create as many spies as you like 9 const spyStomach = sandbox.fn(); 10 const spyPoop = sandbox.spyOn(cow, 'poop'); 11 12 // Clear 'em all with one call 13 beforeEach(() => sandbox.clear()); 14 15 test('Eats grass', () => { 16 return cow.eatGrass.then(spyStomach).then(() => { 17 expect(spyStomach).toHaveBeenCalledWith('????'); 18 expect(spyPoop).toHaveBeenCalledTimes(0); 19 }); 20 }); 21 22 test('Sometimes poops', () => { 23 return cow.digest().then(() => { 24 expect(spyStomach).toHaveBeenCalledTimes(0); 25 expect(spyPoop).toHaveBeenCalledWith('????'); 26 }); 27 }); 28});
1yarn add jest-sandbox -D
Some people prefer npm
;
1npm i jest-sandbox -D
Make a sandbox:
1import createSandbox from 'jest-sandbox'; 2 3const sandbox = createSandbox();
sandbox.fn([implementation])
Returns a new mock function and keeps track of it. Similar to calling jest.fn([implementation])
.
sandbox.spyOn(object, methodName)
Spies on a method and returns a the wrapped mock function. Similar to calling jest.spyOn(object, methodName)
.
sandbox.clear()
Clears all spies in the sandbox. Actually calls .mockClear()
on every spy it keeps track of.
sandbox.reset()
Resets all spies in the sandbox. Actually calls .mockReset()
on every spy it keeps track of.
sandbox.restore()
Restores all spies in the sandbox. Actually calls .mockRestore()
on every spy it keeps track of.
Keep in mind that you can still clear, reset and restore the single spies manually, like you're used to.
I'm happy for every feature request, bugfix and / or PR.
Run tests:
1yarn test # npm test is also ok
Build the whole shebang:
1yarn build # npm build works as well
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 1/18 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- 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
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
76 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-23
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