1.0.1 • Published 3 years ago

jest-if v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

jest-if 🃏🤔

npm build codecov

Conditional test blocks for jest

Installation

With npm:

npm install --save-dev jest-if

or yarn:

yarn add -D jest-if

Setup

Add jest-if to setupFilesAfterEnv in your configuration

module.exports = {
  setupFilesAfterEnv: ['jest-if'],
};

If using TypeScript, you can add the following to your tsconfig to include the necessary type definitions:

{
  "files": ["node_modules/jest-if/index.d.ts"]
}

Usage

Now you can conditionally write tests to be skipped unless the condition returns true:

describe.if(os.platform() !== 'windows')(
  'Unix specific tests can go here',
  () => {
    it('works as expected', () => {
      expect(path.resolve('/')).toEqual('/');
    });
  },
);