Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mattphillips/jest-chain
Chain Jest matchers together to create one powerful assertion 🃏⛓
https://github.com/mattphillips/jest-chain
assertions chain chainable dry expect expressive fail-fast jest matchers
Last synced: 10 days ago
JSON representation
Chain Jest matchers together to create one powerful assertion 🃏⛓
- Host: GitHub
- URL: https://github.com/mattphillips/jest-chain
- Owner: mattphillips
- License: mit
- Created: 2018-05-02T22:21:29.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2023-01-09T08:38:47.000Z (almost 2 years ago)
- Last Synced: 2024-10-15T18:43:49.873Z (24 days ago)
- Topics: assertions, chain, chainable, dry, expect, expressive, fail-fast, jest, matchers
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/jest-chain
- Size: 432 KB
- Stars: 275
- Watchers: 4
- Forks: 16
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-jest - jest-chain
README
jest-chain
🃏⛓
Chain Jest matchers together to create one powerful assertion
[![Build Status](https://img.shields.io/github/workflow/status/mattphillips/jest-chain/GitHub%20CI/main?style=flat-square)](https://github.com/mattphillips/jest-chain/actions/workflows/ci.yaml)
[![Code Coverage](https://img.shields.io/codecov/c/github/mattphillips/jest-chain.svg?style=flat-square)](https://codecov.io/github/mattphillips/jest-chain)
[![version](https://img.shields.io/npm/v/jest-chain.svg?style=flat-square)](https://www.npmjs.com/package/jest-chain)
[![downloads](https://img.shields.io/npm/dm/jest-chain.svg?style=flat-square)](http://npm-stat.com/charts.html?package=jest-chain&from=2017-09-14)
[![MIT License](https://img.shields.io/npm/l/jest-chain.svg?style=flat-square)](https://github.com/mattphillips/jest-chain/blob/master/LICENSE)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
[![Roadmap](https://img.shields.io/badge/%F0%9F%93%94-roadmap-CD9523.svg?style=flat-square)](https://github.com/mattphillips/jest-chain/blob/master/docs/ROADMAP.md)
[![Examples](https://img.shields.io/badge/%F0%9F%92%A1-examples-ff615b.svg?style=flat-square)](https://github.com/mattphillips/jest-chain/blob/master/docs/EXAMPLES.md)- 🍸 Less code duplication
- 🤗 Chain core and custom matchers together
- 👾 Expressive assertions
- 🚨 Fail fast assertions## Problem
Often in [Jest](https://facebook.github.io/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:
```js
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:
```js
it("add 1 and 1", () => {
expect(1 + 1)
.toBe(2)
.toBeGreaterThan(1)
.toBeLessThan(3);
});
```## Installation
With npm:
```sh
npm install --save-dev jest-chain
```With yarn:
```sh
yarn add -D jest-chain
```## Setup
Add `jest-chain` to your Jest `setupFilesAfterEnv` configuration. [See for help](https://jestjs.io/docs/en/next/configuration#setupfilesafterenv-array)
### Jest >v24
```json
"jest": {
"setupFilesAfterEnv": ["jest-chain"]
}
```### Jest