jest-partial
Partial Matcher for Jest Expect
jest-partial
asserts that the provided
object is a subset of the expected
. We don't always want to verify the entire object that has been given. We often just
want to protect the properties that we need, and ignore everything else.
Installation
With npm:
npm install --save-dev jest-partial
With yarn:
yarn add -D jest-partial
Setup
Jest >v24
Add jest-partial
to your Jest setupFilesAfterEnv
configuration. See for help
"jest":
Jest <v23
"jest":
If you are already using another test framework, like jest-chain, then you should create a test setup file and require
each of the frameworks you are using.
For example:
// ./testSetup.js;;;
Then in your Jest config:
"jest":
Typescript
If your editor does not recognise the custom jest-partial
matchers, add a global.d.ts
file to your project with:
;
API
The examples below use the following data object:
const kitchen = version: '1' floor: material: 'wood' color: 'walnut' drawers: contents: type: 'spoon' count: 4 type: 'fork' count: 2 ;
.toMatchPartial(object)
case: Our kitchen has multiple drawers, and we just want to know that there is at least one drawer that contains spoons.
;
case: Our kitchen has multiple drawers, and we want to know that there is a drawer that holds 2 forks.
;
case: Our kitchen has multiple drawers, and we want to know that there is a drawer that holds forks and spoons.
;
Contributors ✨
Thanks goes to these wonderful people (emoji key):
Stephan Meijer 🤔 💻 🚇 🚧 |
This project follows the all-contributors specification. Contributions of any kind welcome!