
Security News
PodRocket Podcast: Inside the Recent npm Supply Chain Attacks
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
jest-partial
Advanced tools
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
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.
With npm:
npm install --save-dev jest-partial
With yarn:
yarn add -D jest-partial
Add jest-partial
to your Jest setupFilesAfterEnv
configuration. See for help
"jest": {
"setupFilesAfterEnv": ["jest-partial"]
}
"jest": {
"setupTestFrameworkScriptFile": "jest-partial"
}
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
require('jest-partial');
require('jest-chain');
require('any other test framework libraries you are using');
Then in your Jest config:
"jest": {
"setupTestFrameworkScriptFile": "./testSetup.js"
}
If your editor does not recognise the custom jest-partial
matchers, add a global.d.ts
file to your project with:
import 'jest-partial';
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 },
],
},
],
};
case: Our kitchen has multiple drawers, and we just want to know that there is at least one drawer that contains spoons.
expect(kitchen).toMatchPartial({
drawers: [
{
contents: [{ type: 'spoon' }],
},
],
});
case: Our kitchen has multiple drawers, and we want to know that there is a drawer that holds 2 forks.
expect(kitchen).toMatchPartial({
drawers: [
{
contents: [{ type: 'fork', count: 2 }],
},
],
});
case: Our kitchen has multiple drawers, and we want to know that there is a drawer that holds forks and spoons.
expect(kitchen).toMatchPartial({
drawers: [
{
contents: [{ type: 'fork' }, { type: 'spoon' }],
},
],
});
Thanks goes to these wonderful people (emoji key):
Stephan Meijer 🤔 💻 🚇 🚧 |
This project follows the all-contributors specification. Contributions of any kind welcome!
FAQs
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
The npm package jest-partial receives a total of 45 weekly downloads. As such, jest-partial popularity was classified as not popular.
We found that jest-partial demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.