jest-extended-plus
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-beta.1 • Public • Published

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])
})

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

Package Sidebar

Install

npm i jest-extended-plus

Weekly Downloads

1

Version

1.0.0-beta.1

License

MIT

Unpacked Size

22.5 kB

Total Files

21

Last publish

Collaborators

  • miyauci