# chai-subset

> Object properties matcher for Chai

Latest version **1.6.0** (published 2017-09-05) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install chai-subset
pnpm add chai-subset
yarn add chai-subset
bun add chai-subset
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.6.0 |
| Published | 2017-09-05 |
| First published | 2014-07-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/chai-subset) |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 83 |
| Author | Andrii Shumada |
| Maintainers | eagleeye |
| Keywords | chai, chai-plugin, objects, subset, contains, plugin, containSubset, deep, like, match, similar, includes, superset |

## Links

- npm: https://www.npmjs.com/package/chai-subset
- Repository: https://github.com/debitoor/chai-subset
- Issues: https://github.com/debitoor/chai-subset/issues
- npm.io page: https://npm.io/package/chai-subset

## Recent versions

- 1.6.0 (latest) — 2017-09-05
- 1.5.0 — 2017-03-02
- 1.4.0 — 2016-12-26
- 1.3.0 — 2016-07-16
- 1.2.2 — 2016-03-22
- 1.2.1 — 2016-02-19
- 1.2.0 — 2015-12-02
- 1.1.0 — 2015-08-29
- 1.0.1 — 2015-05-28
- 1.0.0 — 2015-03-24
- 0.3.0 — 2014-08-03
- 0.2.0 — 2014-08-01
- 0.1.3 — 2014-07-15
- 0.1.2 — 2014-07-14
- 0.1.1 — 2014-07-14
- … 1 more at https://npm.io/package/chai-subset/versions

## README

chai-subset [![npm version](https://badge.fury.io/js/chai-subset.svg)](https://badge.fury.io/js/chai-subset) [![Build Status](https://travis-ci.org/debitoor/chai-subset.svg?branch=master)](https://travis-ci.org/debitoor/chai-subset) [![devDependency Status](https://david-dm.org/debitoor/chai-subset/dev-status.svg)](https://david-dm.org/debitoor/chai-subset#info=devDependencies) [![Coverage Status](https://coveralls.io/repos/debitoor/chai-subset/badge.svg?service=github)](https://coveralls.io/github/debitoor/chai-subset) [![NSP Status](https://nodesecurity.io/orgs/debitoor/projects/eb6fec04-2b26-4462-b4ff-08d952da3065/badge)](https://nodesecurity.io/orgs/debitoor/projects/eb6fec04-2b26-4462-b4ff-08d952da3065)
===========

"containSubset" object properties matcher for [Chai](http://chaijs.com/) assertion library

Installation
===========

`npm install --save-dev chai-subset`

Usage
=====

common.js
```js
var chai = require('chai');
var chaiSubset = require('chai-subset');
chai.use(chaiSubset);
```

in your spec.js
```js
var obj = {
	a: 'b',
	c: 'd',
	e: {
		foo: 'bar',
		baz: {
			qux: 'quux'
		}
	}
};
	
expect(obj).to.containSubset({
	a: 'b',
	e: {
		baz: {
			qux: 'quux'
		}
	}
});

// or using a compare function
expect(obj).containSubset({
	a: (expectedValue) => expectedValue,
	c: (expectedValue) => expectedValue === 'd'
})

// or with 'not'
expect(obj).to.not.containSubset({
	g: 'whatever'
});
```

Also works good with arrays and `should` interface
```js
var list = [{a: 'a', b: 'b'}, {v: 'f', d: {z: 'g'}}];

list.should.containSubset([{a:'a'}]); //Assertion error is not thrown
list.should.containSubset([{a:'a',  b: 'b'}]); //Assertion error is not thrown

list.should.containSubset([{a:'a', b: 'bd'}]); 
/*throws
AssertionError: expected
[
    {
        "a": "a",
        "b": "b"
    },
    {
        "v": "f",
        "d": {
            "z": "g"
        }
    }
]
to contain subset 
[ { a: 'a', b: 'bd' } ]
*/
```

and with `assert` interface
```js
assert.containSubset({a: 1, b: 2}, {a: 1});
```

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