npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jest-partial

v1.0.1

Published

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

Downloads

217

Readme

jest-partial

All Contributors

Partial Matcher for Jest Expect

animation of jest-partial matcher

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": {
  "setupFilesAfterEnv": ["jest-partial"]
}

Jest <v23

"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"
}

Typescript

If your editor does not recognise the custom jest-partial matchers, add a global.d.ts file to your project with:

import 'jest-partial';

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.

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' }],
    },
  ],
});

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!