Installations
npm install jest-sandbox
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
8.9.4
NPM Version
5.6.0
Score
70.6
Supply Chain
98.4
Quality
81.1
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
JoinColony
Download Statistics
Total Downloads
1,067,576
Last Day
516
Last Week
2,141
Last Month
8,526
Last Year
111,605
GitHub Statistics
16 Stars
28 Commits
1 Forks
6 Watching
283 Branches
7 Contributors
Bundle Size
476.00 B
Minified
263.00 B
Minified + Gzipped
Package Meta Information
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
Total Downloads
Cumulative downloads
Total Downloads
1,067,576
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
jest-sandbox
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.
Meet jest-sandbox:
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});
Install
1yarn add jest-sandbox -D
Some people prefer npm
;
1npm i jest-sandbox -D
API
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.
Note
Keep in mind that you can still clear, reset and restore the single spies manually, like you're used to.
Contribute
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
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
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
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 12 are checked with a SAST tool
Reason
75 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-8w4h-3cm3-2pm2
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-hr2v-3952-633q
- Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9
- Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2
- Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3
- Warn: Project is vulnerable to: MAL-2023-462
- Warn: Project is vulnerable to: GHSA-xf7w-r453-m56c
- Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq
- Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm
- Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3
- Warn: Project is vulnerable to: GHSA-f9cm-qmx5-m98h
- Warn: Project is vulnerable to: GHSA-7wpw-2hjm-89gp
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-fhjf-83wg-r2j9
- Warn: Project is vulnerable to: GHSA-w9mr-4mfr-499f
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-6394-6h9h-cfjg
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-6g33-f262-xjp4
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-jv35-xqg7-f92r
- Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp
- Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr
- Warn: Project is vulnerable to: GHSA-2m39-62fm-q8r3
- Warn: Project is vulnerable to: GHSA-mf6x-7mm4-x2g7
- Warn: Project is vulnerable to: GHSA-j44m-qm6p-hp7m
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-g7q5-pjjr-gqvp
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
2
/10
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 MoreOther packages similar to 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