chai-subset
    Overview
    Documentation
    Tutorials
    Insights
    Code
    Dependencies
    Contributors
    Jobs

chai-subset

Object properties matcher for Chai

1.6.0  •  Updated 3 years ago  •  by debitoor  •  MIT License

chai-subset npm version Build Status devDependency Status Coverage Status NSP Status

“containSubset” object properties matcher for Chai assertion library

Installation

npm install --save-dev chai-subset

Usage

common.js

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

in your spec.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

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

assert.containSubset({a: 1, b: 2}, {a: 1});

Popularity

Weekly Downloads
82.7K
Stars
74

Maintenance

Development

Last ver 3 years ago
Created 6 years ago
Last commit 3 years ago
14 days between commits

Technology

Node version: 6.11.1
0 unpacked

Compliance

MIT License
OSI Approved
0 vulnerabilities

Contributors

12 contributors
Andrii Shumada
60 commits, 34 merges, 10 PRs
Works at Everad
greenkeeperio-bot
15 commits, 23 PRs
Works at greenkeeperio
Alex Bubenshchykov
3 commits
Works at Google
RobertHerhold
2 commits, 2 PRs
Works at BadgeUp
Denis Gorbachev
1 commits, 1 PRs
Works at Spire
Keith Cirkel
1 commits, 1 PRs

Tags

chai
chai-plugin
objects
subset
contains
plugin
containSubset
deep
like
match
similar
includes
superset
Openbase helps developers choose among and use millions of open-source packages, so they can build amazing products faster.
FacebookTwitterLinkedIn
© 2020 Devstore, Inc.