Package Exports
- jest-extended-plus
- jest-extended-plus/all
Readme
jest-extended-plus
🃏💪➕
Additional more Jest matchers
What
It is a matcher collection which is a further extension of jest-extended and is recommended to be used together with jest-extended
.
Installation
With npm:
npm i --save-dev jest-extended-plus
With yarn:
yarn add -D jest-extended-plus
Setup
Note that jest-extended-plus
only supports Jest version 24 and newer.
// ./testSetup.js
// add all jest-extended-plus matchers
import * as matchers from 'jest-extended-plus'
expect.extend(matchers)
// or just add specific matchers
import { toEqualOneOf } from 'jest-extended-plus'
expect.extend({ toEqualOneOf })
Add your setup script to your Jest setupFilesAfterEnv
configuration. See for help
"jest": {
"setupFilesAfterEnv": ["./testSetup.js"]
}
To automatically extend expect
with all matchers, you can use
"jest": {
"setupFilesAfterEnv": ["jest-extended-plus/all"]
}
Typescript
If your editor does not recognise the custom jest-extended-plus
matchers, add a global.d.ts
file to your project with:
import 'jest-extended-plus'
You must update your tsconfig.json
to include the new global.d.ts
file in the files
property like so:
{
"compilerOptions": {
...
},
...
"files": ["global.d.ts"]
}
Also note that when adding this for the first time this affects which files are compiled by the TypeScript compiler and you might need to add the include
property as well. See the TypeScript docs for more details.
If the above import syntax does not work, replace it with the following:
/// <reference types="jest-extended-plus" />
API
.toEqualOneOf([members])
Use .toEqualOneOf
when checking if a value equal to a member of a given Array
.
test('passes when value is in given array', () => {
expect(1).toEqualOneOf([expect.any(Number), null])
expect(undefined).not.toEqualOneOf([expect.any(Number), null])
})
.toBeNumberOrNull()
Use .toBeNumberOrNull
when checking if a value is a number
or null
.
test('passes when value is a number or null', () => {
expect(0).toBeNumberOrNull()
expect(null).toBeNumberOrNull()
expect(undefined).not.toBeNumberOrNull()
})
.toBeStringOrNull([members])
Use .toBeStringOrNull
when checking if a value is a string
or null
.
test('passes when value is a string or null', () => {
expect('').toBeStringOrNull()
expect(null).toBeStringOrNull()
expect(true).not.toBeStringOrNull()
})
Contributing
Contributions, issues and feature requests are welcome!
Feel free to check
issues.
Show your support
Give a ⭐️ if this project helped you!

License
Copyright © 2021-present TomokiMiyauci.
Released under the MIT license