Security News
CISA Brings KEV Data to GitHub
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
jest-skip-if
Advanced tools
This package is created to handle the use case when you need to conditionally skip or test a spec in jest.
yarn add --dev jest jest-skip-if
With jest-skip-if
installed you can either use it on individual files or add it globally.
For individual files you can import and use it directly.
import {skipIf} from 'jest-skip-if';
skipIf(true, 'skipped spec', () => {})
Or, if desired it can be setup globally by adding or modifying a setup script with Jest's setupFilesAfterEnv
configuration.
// testSetup.js
import {skipIf, testIf} from 'jest-skip-if';
global.skipIf = skipIf;
global.testIf = testIf;
"jest": {
"setupFilesAfterEnv": ["./testSetup.js"]
}
If desired, you can also add jest-skip-if
setup file to your setupFilesAfterEnv
array.
"jest": {
"setupFilesAfterEnv": ["jest-skip-if/setup"]
}
skipIf
When there is a use case that you need to skip a spec based off of a condition you can use skipIf
skipIf(hasFeatureEnabled, 'spec using feature', () => {
// Nothing is run given hasFeatureEnabled is true
expect(true).toBe(true);
})
In the example, hasFeatureEnabled
can be both a boolean
or a function returning a boolean
.
testIf
When there is a use case that you need to test a spec based off of a condition you can use testIf
testIf(hasFeatureEnabled, 'spec using feature', () => {
// Spec is run given hasFeatureEnabled is true
expect(true).toBe(true);
})
In the example, hasFeatureEnabled
can be both a boolean
or a function returning a boolean
.
FAQs
Allow for a condition to skip or run specs in Jest
We found that jest-skip-if 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
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.