
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
jest-test-matrix
Advanced tools
A small utility for Jest to test all combinations of parameters for a function at once.
A plugin for Jest which helps you test functions accepting different combinations of inputs. Instead of manually writing a test for each possible combination, you will only need to write one.
A quick example:
// file.test.js
import testMatrix from 'jest-test-matrix';
interface CanPayOpts {
amount: number;
balance: number;
status: 'active' | 'locked' | 'expired';
}
function canPay({amount, balance, status}: CanPayOpts){
if (status === 'locked' || status == 'expired'){
return false;
}
return balance > amount;
}
it('should only allow valid payments', () => {
expect(
testMatrix(canPay, {
amount: [20, 100],
balance : [50],
status: ['active', 'locked', 'expired']
})
).toMatchSnapshot();
})
will result in the following snapshot:
// file.test.snap
exports[`should only allow valid payments 1`] = `
.-------------------------------------.
| canPay |
|-------------------------------------|
| balance | amount | status | result |
|---------|--------|---------|--------|
| 50 | 20 | active | true |
| | | locked | false |
| | | expired | false |
| | 100 | active | false |
| | | locked | false |
| | | expired | false |
'-------------------------------------'
`;
With npm
npm install -D jest-test-matrix
With yarn
yarn add -D jest-test-matrix
testMatrix(fn, input)
where
fn: (params: Record<'string', any>) => any
: The function you want to test. By default, all the parameters in input
are passed as an object. If your function has a different arity, you can always pass an anonymous function wrapping your own function, like so testMatrix({a, b} => fn(a, b), {a: [...], b: [...]})
. If your function has a name, it will be used as a title in the matrix snapshot.input: Record<'string', any[]>
: An object where keys are the names of the parameters you want to test (they will be used as column headers in the snapshot), and values are an array of different possible values for each parameter.The call to testMatrix
should we wrapped in a jest.expect
call to generate a snapshot:
expect(
testMatrix(canPay, {
amount: [20, 100],
balance : [50],
status: ['active', 'locked', 'expired']
})
).toMatchSnapshot();
FAQs
A small utility for Jest to test all combinations of parameters for a function at once.
The npm package jest-test-matrix receives a total of 733 weekly downloads. As such, jest-test-matrix popularity was classified as not popular.
We found that jest-test-matrix 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
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.