Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
jest-test-each
Advanced tools
run parametrised tests easily [typesafe] without text tables or arrays of arrays.
This package will help you to run parametrised tests easily [typesafe] without text tables or arrays of arrays.
You can see demo project here.
Tests are here.
its('roundings')
.each([
{ input: 0, expected: '0' },
{ input: 0.99, expected: '1' },
{ input: 102.99998, expected: '103' },
{ input: -6, expected: '-6' },
])
.run(t => {
expect(Math.round(t.input).toFixed(0)).toBe(t.expected);
});
Run test in idea with jest plugin:
its('check calculator')
.each([
{ a: 1, b: 2, exp: [3, -1, 2, 0.5] },
{ a: 1, b: 0, exp: [1, 1, 0, Infinity] },
])
.each(t => [
{ sign: '+' as const, exp: t.exp[0] },
{ sign: '-' as const, exp: t.exp[1] },
{ sign: '*' as const, exp: t.exp[2] },
{ sign: '/' as const, exp: t.exp[3] },
])
.each(t => [{ flatDesc: `${t.a} ${t.sign} ${t.b} should be ${t.exp}` }])
.run(async t => {
expect(calc(t.a, t.b, t.sign)).toBe(t.exp);
});
and the same test with auto cases names:
Install dev dependency:
yarn add -D jest-test-each
To setup jest you need to have jest.config.js config (official details)
In your jest.config.js config add:
// jest.config.js
module.exports = {
...
setupFilesAfterEnv: ["./config/setup.js"],
...
};
In './config/setup.js' file add the following (this is required for global vars to be available):
require('jest-test-each');
for .ts tests to see globals 'its' and 'Test' add the following to your tsconfig:
// tsconfig.json
"include": [
...
"node_modules/jest-test-each/dist/index.d.ts"
]
You can override test runner environment (by default it is jest env) by the following:
TestEachEnv({
describe: describe,
it: it,
beforeAll: beforeAll,
...
});
.each().each()....run()
)its('foo').run(..)
).only(<filter>)
) (example).See example.
Running the feature containing this will result in 2 tests
its('Simple test: roundings')
.each([
{ input: 0, expected: '0' },
{ input: 0.99, expected: '1' },
{ input: 102.99998, expected: '103' },
{ input: -6, expected: '-6' },
])
.only(t => t.input === -6)
.run(t => {
expect(Math.round(t.input).toFixed(0)).toBe(t.expected);
});
Supporting jest 27.
Working with Skip and Defect:
test-runner: "jest-jasmine2"
FAQs
run parametrised tests easily [typesafe] without text tables or arrays of arrays.
We found that jest-test-each 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.