New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jest-skip-if

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-skip-if

Allow for a condition to skip or run specs in Jest

  • 0.1.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

jest-skip-if

This package is created to handle the use case when you need to conditionally skip or test a spec in jest.

Installation

yarn add --dev jest jest-skip-if 

Setup

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"]
}

Helpers

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.

Keywords

FAQs

Package last updated on 22 Jul 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc