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
70.6
Supply Chain
98.4
Quality
81.1
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
1,067,576
Last Day
516
Last Week
2,141
Last Month
8,526
Last Year
111,605
16 Stars
28 Commits
1 Forks
6 Watching
283 Branches
7 Contributors
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
Publised On
19 Feb 2018
Cumulative downloads
Total Downloads
Last day
39.5%
516
Compared to previous day
Last week
11.9%
2,141
Compared to previous week
Last month
-3.8%
8,526
Compared to previous month
Last year
-14.5%
111,605
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
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/18 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
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
75 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