Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chai-subset

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chai-subset

Object properties matcher for Chai

  • 1.6.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
284K
increased by1.06%
Maintainers
1
Weekly downloads
 
Created

What is chai-subset?

chai-subset is a plugin for the Chai assertion library that allows you to assert that a JavaScript object contains a subset of properties. This is particularly useful for testing partial matches in objects, arrays, and nested structures.

What are chai-subset's main functionalities?

Object Subset Matching

This feature allows you to check if an object contains a subset of properties. In the example, the object `obj` is checked to see if it contains the properties `a` and `b` with the specified values.

const chai = require('chai');
const chaiSubset = require('chai-subset');
chai.use(chaiSubset);
const expect = chai.expect;

const obj = { a: 1, b: 2, c: 3 };
expect(obj).to.containSubset({ a: 1, b: 2 });

Array Subset Matching

This feature allows you to check if an array contains a subset of objects. In the example, the array `arr` is checked to see if it contains objects with the properties `a` and `b`.

const chai = require('chai');
const chaiSubset = require('chai-subset');
chai.use(chaiSubset);
const expect = chai.expect;

const arr = [{ a: 1 }, { b: 2 }, { c: 3 }];
expect(arr).to.containSubset([{ a: 1 }, { b: 2 }]);

Nested Object Subset Matching

This feature allows you to check if a nested object contains a subset of properties. In the example, the nested object `nestedObj` is checked to see if it contains the nested properties `a.b.c` with the specified value.

const chai = require('chai');
const chaiSubset = require('chai-subset');
chai.use(chaiSubset);
const expect = chai.expect;

const nestedObj = { a: { b: { c: 3 } } };
expect(nestedObj).to.containSubset({ a: { b: { c: 3 } } });

Other packages similar to chai-subset

Keywords

FAQs

Package last updated on 05 Sep 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc