https://github.com/d4nyll/jest-matcher-one-of
A Jest matcher to test if a value is one of many (like enums).
https://github.com/d4nyll/jest-matcher-one-of
Last synced: about 1 year ago
JSON representation
A Jest matcher to test if a value is one of many (like enums).
- Host: GitHub
- URL: https://github.com/d4nyll/jest-matcher-one-of
- Owner: d4nyll
- License: mit
- Created: 2017-11-18T13:17:30.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-06-04T21:36:56.000Z (almost 2 years ago)
- Last Synced: 2025-03-26T15:48:07.942Z (about 1 year ago)
- Language: JavaScript
- Size: 776 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jest-matcher-one-of
[](https://travis-ci.org/d4nyll/jest-matcher-one-of)
[](https://codecov.io/gh/d4nyll/jest-matcher-one-of)
[](https://codeclimate.com/github/d4nyll/jest-matcher-one-of/test_coverage)
[](https://www.codefactor.io/repository/github/d4nyll/jest-matcher-one-of)
[](https://www.codacy.com/app/d4nyll/jest-matcher-one-of?utm_source=github.com&utm_medium=referral&utm_content=d4nyll/jest-matcher-one-of&utm_campaign=Badge_Grade)
[](https://codeclimate.com/github/d4nyll/jest-matcher-one-of/maintainability)
[](https://snyk.io/test/github/d4nyll/jest-matcher-one-of)
[](https://greenkeeper.io/)
A Jest matcher (`toBeOneOf`) to test if a value is one of many (like enums).
## Installation
1. Add the package
```sh
yarn add jest-matcher-one-of --dev
npm install jest-matcher-one-of --save-dev
```
2. Require the package at the root of your test files
```js
require('jest-matcher-one-of');
import 'jest-matcher-one-of'; // Using ES6 w/ Babel or TypeScript
```
## Usage
```js
expect(1).toBeOneOf([1, 2]);
expect(1).not.toBeOneOf([2, 3, 4]);
expect(1).toBeOneOf(1); // Also forgiving for non-array values
```
## Contributing
Get the source code and run the tests.
```sh
$ git clone git@github.com:d4nyll/jest-matcher-one-of.git
$ yarn # or npm install
$ yarn test # or npm test
```