# extend-expect

> Types and a helper for extending Jest's expect

Latest version **3.0.0** (published 2024-01-03) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install extend-expect
pnpm add extend-expect
yarn add extend-expect
bun add extend-expect
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2024-01-03 |
| First published | 2022-09-03 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 54.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Andrew Aylett |
| Maintainers | andrewaylett |

## Links

- npm: https://www.npmjs.com/package/extend-expect
- Repository: https://github.com/andrewaylett/extend-expect
- Homepage: https://github.com/andrewaylett/extend-expect#readme
- Issues: https://github.com/andrewaylett/extend-expect/issues
- npm.io page: https://npm.io/package/extend-expect

## Recent versions

- 3.0.0 (latest) — 2024-01-03
- 2.0.1 — 2023-12-22
- 2.0.0 — 2023-12-22
- 1.3.0 — 2023-11-28
- 1.2.0 — 2023-09-16
- 1.1.0 — 2023-09-16
- 1.0.2 — 2022-09-10
- 1.0.1 — 2022-09-09
- 1.0.0 — 2022-09-04
- 0.2.0 — 2022-09-03
- 0.1.0 — 2022-09-03

## README

# Extend Expect

Helpers for extending Jest's `expect` in a type-safe manner in Typescript.

## Rationale

Extending Jest's matchers makes for much easier testing, but convincing
Typescript that you've done so is annoying. The types you need are mostly, but
not exhaustively, defined in the type stubs but aren't available for import.

This package is mostly type manipulation.
We extract the relevant types from Jest, and package them up into a wrapper
function which calls `expect.extend()` then returns `expect`.

## Use

Recommended usage follows the pattern in
[src/test/expect.ts](test/expect.ts).
You need an interface which denotes the extra methods you're making available on
the object returned from `expect()`, and an object implementing the matchers
corresponding to the members of the interface.

Importantly, you don't implement the extension interface:
Jest will mangle calls made to it by test code, and call the correct underlying
matcher function.

Jest has [more documentation on writing custom
matchers](https://jestjs.io/docs/expect#expectextendmatchers).
The utility functions available on `this.util` are particularly useful for
making nice failure messages.

## Releasing

We use `npm versions` and GitHub Actions to release.

On your local machine, with `main` checked out,
run `npm version patch` or whatever bump is appropriate.
This will create a new commit and a tag starting with `v` containing the
version.
Push the tag to GitHub.
We protect tags starting with `v`, so this step may only be undertaken by
repository administrators.

In the GitHub UI, wait until the tag has finished its CI build.
Now we may push the `main` branch without hitting branch protections.
Do so.

Again in the GitHub UI, find the tag.
Use the three dot menu on the tag to create a release.
Use the auto-fill button to populate the release notes, and publish the release.

GitHub Actions will now build the release and publish it to NPM.

---
_Source: https://npm.io/package/extend-expect · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
