
Security News
High Salaries No Longer Enough to Attract Top Cybersecurity Talent
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
jest-chance
Advanced tools
A small library to help javascript projects deal with reproducible randomised test data.
Tested with:
![]()
yarn add -D jest-chance
npm install -D jest-chance
To have a random seed for each test execution, we need to tell Jest to use this library.
In your package.json
, add the following:
"jest": {
"globalSetup": "jest-chance"
}
Within your tests, you might have something like this:
Old Chance usage, don't copy this
import Chance from 'chance'; const chance = new Chance();
This will be replaced by our new package's offering:
import { chance } from 'jest-chance';
This will do 2 things:
### Using with a fixed seed
Sometimes you would need deterministic generators.
For that reason, you can use the method: getChance(seed?)
import { getChance } from 'jest-chance';
const deterministicChance = getChance('a-fixed-seed');
When you run your tests, jest will tell you something like this:
Using Chance Seed: 534a873a618e4e317060f9bc29f9115ad156168b
This is the piece of information you need to replay the tests with the same values.
Set the CHANCE_SEED
environment variable to the seed you got in the console previously
$ CHANCE_SEED=534a873a618e4e317060f9bc29f9115ad156168b jest
There's more to follow, this is a WIP project. Feel free to contribute with pull requests.
FAQs
Random seed generator for chancejs with jest
We found that jest-chance demonstrated a not healthy version release cadence and project activity because the last version was released 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
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Product
Socket, the leader in open source security, is now available on Google Cloud Marketplace for simplified procurement and enhanced protection against supply chain attacks.
Security News
Corepack will be phased out from future Node.js releases following a TSC vote.