All Projects β†’ atlassian β†’ Jest In Case

atlassian / Jest In Case

Licence: mit
Jest utility for creating variations of the same test

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Jest In Case

Javascript Testing Best Practices
πŸ“—πŸŒ 🚒 Comprehensive and exhaustive JavaScript & Node.js testing best practices (August 2021)
Stars: ✭ 13,976 (+1449.45%)
Mutual labels:  jest, test
Jest Html Reporters
🌈 Reporter for jest test framework. 🌈
Stars: ✭ 245 (-72.84%)
Mutual labels:  jest, test
Jest Html Reporter
Jest test results processor for generating a summary in HTML
Stars: ✭ 161 (-82.15%)
Mutual labels:  jest, test
Tyu
Unit test with no initial configuration.
Stars: ✭ 89 (-90.13%)
Mutual labels:  jest, test
walrus
πŸŽ‰ Cli development framework.
Stars: ✭ 17 (-98.12%)
Mutual labels:  jest, test
Gest
πŸ‘¨β€πŸ’» A sensible GraphQL testing tool - test your GraphQL schema locally and in the cloud
Stars: ✭ 109 (-87.92%)
Mutual labels:  jest, test
Jest Expect Message
Add custom message to Jest expects πŸƒπŸ—―
Stars: ✭ 240 (-73.39%)
Mutual labels:  jest, test
Esbuild Jest
A Jest transformer using esbuild
Stars: ✭ 100 (-88.91%)
Mutual labels:  jest, test
jest-launchdarkly-mock
Easily unit test LaunchDarkly feature flagged components with jest
Stars: ✭ 14 (-98.45%)
Mutual labels:  jest, test
xv
❌ βœ”οΈ zero-config test runner for simple projects
Stars: ✭ 588 (-34.81%)
Mutual labels:  jest, test
React Generate Props
Generate default props based on your React component's PropTypes
Stars: ✭ 23 (-97.45%)
Mutual labels:  jest, test
puppeteer-screenshot-tester
Small library that allows us to compare screenshots generated by puppeteer in our tests.
Stars: ✭ 50 (-94.46%)
Mutual labels:  jest, test
Snap Shot
Jest-like snapshot feature for the rest of us, works magically by finding the right caller function
Stars: ✭ 170 (-81.15%)
Mutual labels:  jest, test
Vuex Mock Store
βœ…Simple and straightforward Vuex Store mock for vue-test-utils
Stars: ✭ 246 (-72.73%)
Mutual labels:  jest, test
reducer-tester
Utilities for testing redux reducers
Stars: ✭ 19 (-97.89%)
Mutual labels:  jest, test
Enzyme
JavaScript Testing utilities for React
Stars: ✭ 19,781 (+2093.02%)
Mutual labels:  jest, test
Gogradle
A Gradle Plugin Providing Full Support for Go
Stars: ✭ 712 (-21.06%)
Mutual labels:  test
Webdriverio
Next-gen browser and mobile automation test framework for Node.js
Stars: ✭ 7,214 (+699.78%)
Mutual labels:  test
Eslint Plugin Jest
ESLint plugin for Jest
Stars: ✭ 699 (-22.51%)
Mutual labels:  jest
Specs2
Software Specifications for Scala
Stars: ✭ 696 (-22.84%)
Mutual labels:  test

jest-in-case

Jest utility for creating variations of the same test

Example

import { add, subtract } from './math';
import cases from 'jest-in-case';

cases('add(augend, addend)', opts => {
  expect(add(opts.augend, opts.addend)).toBe(opts.total);
}, [
  { name: '1 + 1 = 2', augend: 1, addend: 1, total: 2 },
  { name: '2 + 1 = 3', augend: 2, addend: 1, total: 3 },
  { name: '3 + 1 = 4', augend: 3, addend: 1, total: 4 },
]);

Installation

yarn add --dev jest-in-case

Usage

In your Jest tests, import cases from jest-in-case.

import cases from 'jest-in-case';
// or
const cases = require('jest-in-case');

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

cases(title, tester, testCases);

testCases can either be an array of objects with a name property:

cases('add(augend, addend)', opts => {
  expect(add(opts.augend, opts.addend)).toBe(opts.total);
}, [
  { name: '1 + 1 = 2', augend: 1, addend: 1, total: 2 },
  { name: '2 + 1 = 3', augend: 2, addend: 1, total: 3 },
  { name: '3 + 1 = 4', augend: 3, addend: 1, total: 4 },
]);

Or an object of objects with the names as the keys:

cases('subtract(minuend, subtrahend)', opts => {
  expect(subtract(opts.minuend, opts.subtrahend)).toBe(opts.difference);
}, {
  '1 - 1 = 0': { minuend: 1, subtrahend: 1, difference: 0 },
  '2 - 1 = 1': { minuend: 2, subtrahend: 1, difference: 1 },
  '3 - 1 = 2': { minuend: 3, subtrahend: 1, difference: 2 },
});

Inside of a test case you can put whatever properties you want, except for name, only, or skip:

cases('title', fn, [
  { name: 'reserved 1', only: true, skip: true, whatever: 'you', want: 'here' },
  { name: 'reserved 2', only: true, skip: true, whatever: 'you', want: 'here' },
  { name: 'reserved 3', only: true, skip: true, whatever: 'you', want: 'here' },
]);
  • name is passed to test(name, fn) to become the name of your test
  • When only is set to true it will use Jest's test.only function
  • When skip is set to true it will use Jest's test.skip function

The tester function is called on each test case with your options:

cases('title', opts => {
  console.log('passed: ', opts);
}, {
  'test 1': { foo: 1 },
  'test 2': { bar: 2 },
  'test 3': { baz: 3 },
});

// passed: { foo: 1 }
// passed: { bar: 2 }
// passed: { baz: 3 }

Your tester function works just like functions passed to Jest's test function do (Just with a prepended argument):

cases('async functions', async opts => {
  let result = await somethingAsync(opts.input);
  expect(result).toEqual(opts.result);
}, {
  'test 1': { ... },
  'test 2': { ... },
});

cases('done callback', (opts, done) => {
  somethingAsync(opts.input, result => {
    expect(result).toEqual(result);
    done();
  });
}, {
  'test 1': { ... },
  'test 2': { ... },
});
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].