Socket
Book a DemoInstallSign in
Socket

jest-tc

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

jest-tc

Test cases for Jest with built-in TypeScript support.

1.1.1
unpublished
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

jest-cases

Test cases for Jest with built-in TypeScript support.

Getting Started

It's super easy to install and to use - you'll love it!

Install from NPM as a dev dependency:

npm i -D jest-tc

Include in your test files where you need it:

import cases from 'jest-tc'   // for ES6
const cases = require('jest-tc')  // for CommonJS

Then you can call cases with a title, a tester function, and some testCases:

cases(
  title: string,
  tester: (args: TestCase) => void,
  testCases: TestCase[] | { [name: string]: TestCase }): void

TestCase

A test case is an object that has this structure:

  • name?: string - the name of the test case
  • skip?: boolean - modifier, when true skips the test case
  • only?: boolean - modifier, when true on any cases, only those are run
  • [key: string]: any - any extra args to be consumed by tester

tester: (args: TestCase) => void

For every test case, the tester function is run with the TestCase object as its first parameter.

cases('tester Example', args => {
  console.log(args) // logs { name: 'First', whatever: 'args', you: 'want' }, ...
}, [
  { name: 'First', whatever: 'args', you: 'want' },
  { name: 'Second', whatever: 'args', you: 'want' }
])

testCases: TestCase[]

testCases can either be an array of TestCase or an object whose keys are the names of the tests.

As an array, testCases: TestCase[], test cases can optionally have a name property which is defined as the array index when excluded:

cases('Array Example', args => {
  expect(args.value).toBe(args.expected)
}, [
  { name: 'First', value: 60, expected: 65 },   // "First" will fail
  { value: 55, expected: 55 },                  // "1" will pass
  { value: 40, expected: 42 }                   // "2" will fail
])

testCases: { [name: string]: TestCase }

Here's an example of the testCases param as an object:

cases('Object Example', args => {
  expect(args.value).toBe(args.expected)
}, {
  'First': { value: 60, expected: 65 },   // "First" will fail
  '1': { value: 55, expected: 55 },       // "1" will pass
  '2': { value: 40, expected: 42 }        // "2" will fail
}

Modifiers

Following are the available modifiers and examples for how to use them.

skip

Takes precedence over other modifiers.

cases('Only Example', args => {
  expect(args.value).toBe(args.expected)
}, [
  { ...args },              // Run
  { skip: true, ...args },    // Not Run
  { ...args }               // Run
]

only

cases('Only Example', args => {
  expect(args.value).toBe(args.expected)
}, [
  { ...args },                          // Not Run
  { only: true, ...args },              // Run
  { only: true, skip: true, ...args }   // Not Run
]

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

FAQs

Package last updated on 17 Mar 2020

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.