All Projects → mattphillips → Jest Chain

mattphillips / Jest Chain

Licence: mit
Chain Jest matchers together to create one powerful assertion 🃏⛓

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Jest Chain

Sazerac
Data-driven unit testing for Jasmine, Mocha, and Jest
Stars: ✭ 322 (+37.02%)
Mutual labels:  jest, assertions
Jest Extended
Additional Jest matchers 🃏💪
Stars: ✭ 1,763 (+650.21%)
Mutual labels:  jest, assertions
Enzyme
JavaScript Testing utilities for React
Stars: ✭ 19,781 (+8317.45%)
Mutual labels:  jest, assertions
Expect More
Curried Type Testing library, and Test Matchers for Jest
Stars: ✭ 124 (-47.23%)
Mutual labels:  jest, assertions
Aws Testing Library
Chai (https://chaijs.com) and Jest (https://jestjs.io/) assertions for testing services built with aws
Stars: ✭ 52 (-77.87%)
Mutual labels:  jest, assertions
Redux Actions Assertions
Simplify testing of redux action and async action creators
Stars: ✭ 177 (-24.68%)
Mutual labels:  jest, assertions
Testdeck
Object oriented testing
Stars: ✭ 206 (-12.34%)
Mutual labels:  jest
Testing React Redux With Jest And Enzyme
React Redux Testing Template using Jest and Enzyme
Stars: ✭ 224 (-4.68%)
Mutual labels:  jest
Jest Dom
🦉 Custom jest matchers to test the state of the DOM
Stars: ✭ 2,908 (+1137.45%)
Mutual labels:  jest
Root Cause
🔍 Root Cause is a tool for troubleshooting Puppeteer and Playwright tests. 🔎
Stars: ✭ 205 (-12.77%)
Mutual labels:  jest
Babel Plugin Tester
Utilities for testing babel plugins
Stars: ✭ 228 (-2.98%)
Mutual labels:  jest
Pester
Pester is the ubiquitous test and mock framework for PowerShell.
Stars: ✭ 2,620 (+1014.89%)
Mutual labels:  assertions
Codejam
Set of handy reusable .NET components that can simplify your daily work and save your time when you copy and paste your favorite helper methods and classes from one project to another
Stars: ✭ 217 (-7.66%)
Mutual labels:  assertions
Buefy Shop
A sample shop built with Nuxt, Stripe, Firebase and Serverless Functions
Stars: ✭ 207 (-11.91%)
Mutual labels:  jest
Jest Schematic
Angular schematic for adding Jest and the required files to an Angular CLI project
Stars: ✭ 224 (-4.68%)
Mutual labels:  jest
Front End Guide
📚 Study guide and introduction to the modern front end stack.
Stars: ✭ 14,073 (+5888.51%)
Mutual labels:  jest
Jest Mock Extended
Type safe mocking extensions for Jest https://www.npmjs.com/package/jest-mock-extended
Stars: ✭ 224 (-4.68%)
Mutual labels:  jest
Gotest.tools
A collection of packages to augment the go testing package and support common patterns.
Stars: ✭ 205 (-12.77%)
Mutual labels:  assertions
Svelte Boilerplate
Svelte application boilerplate with Webpack, Babel, PostCSS, Sass, Fetch, Jest, .Env, EsLint.
Stars: ✭ 216 (-8.09%)
Mutual labels:  jest
Sinon Jest Cheatsheet
Some examples on how to achieve the same goal with either of both libraries: sinon and jest. Also some of those goals achievable only by one of these tools.
Stars: ✭ 226 (-3.83%)
Mutual labels:  jest

jest-chain

🃏⛓

Chain Jest matchers together to create one powerful assertion


Build Status Code Coverage version downloads MIT License PRs Welcome Roadmap Examples

  • 🍸 Less code duplication
  • 🤗 Chain core and custom matchers together
  • 👾 Expressive assertions
  • 🚨 Fail fast assertions

Problem

Often in Jest when you are writing tests you may want to perform multiple assertions on the same variable. Currently to achieve this you have to write an individual expect for each assertion.

For example:

it('add 1 and 1', () => {
  const actual = 1 + 1;
  expect(actual).toBe(2);
  expect(actual).toBeGreaterThan(1);
  expect(actual).toBeLessThan(3);
});

With jest-chain this can instead be written by chaining the matchers together:

it('add 1 and 1', () => {
  expect(1 + 1)
    .toBe(2)
    .toBeGreaterThan(1)
    .toBeLessThan(3);
});

Installation

With npm:

npm install --save-dev jest-chain

With yarn:

yarn add -D jest-chain

Setup

Add jest-chain to your Jest setupFilesAfterEnv configuration. See for help

Jest >v24

"jest": {
  "setupFilesAfterEnv": ["jest-chain"]
}

Jest <v23

"jest": {
  "setupTestFrameworkScriptFile": "jest-chain"
}

If you are already using another test framework, like jest-extended, then you should create a test setup file and require each of the frameworks you are using (including jest-chain 😉)

For example:

// ./testSetup.js
require('jest-chain');
require('any other test framework libraries you are using');

Then in your Jest config:

"jest": {
  "setupTestFrameworkScriptFile": "./testSetup.js"
}

Typescript

If your editor does not recognise the chained jest matchers, add a global.d.ts file to your project with:

import 'jest-chain';

Note: if you are using any other custom matcher libraries then make sure that the jest-chain type import is at the bottom so that the types can chain core matchers with your customer matcher library.

Usage

Use Jest's expect function the same way you would normally but with the ability to chain any matcher to another, including nested matchers such as: .not, .resolves and .rejects.

jest-chain supports custom Jest matchers, like jest-extended, in the usual way with expect.extend(matcher). Each of these custom matchers are also chainable.

Some examples:

expect([1, 2, 3])
  .toHaveLength(3)
  .toEqual([1, 2, 3]);
// with jest-extended
expect([1, 2, 3])
  .toBeArray()
  .toBeArrayOfSize(3)
  .toEqual([1, 2, 3])
  .toIncludeAnyMembers([1, 2]);

expect(100)
  .toBePositive()
  .toBeGreaterThan(99)
  .toBeLessThan(101)
  .toBeNumber()
  .not.toBeNaN()
  .toBe(100);

expect('hello world')
  .toBeString()
  .toEqualCaseInsensitive('HELLO WORLD')
  .toStartWith('hello')
  .toEndWith('world')
  .not.toInclude('!')
  .toBe('hello world');

Matcher failures will fail fast from left to right, they have no impact on each other. 🎉

Note: jest-chain does not currently support asymmetric matcher chaining, if you want this please send a PR 😊

LICENSE

MIT

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].