/chai-shallow-deep-equal

Shallow deep equal for chai

Primary LanguageJavaScript

chai-datetime

Will shallowly perform a deep equal assertion. In other terms is consit of checking that an object, or objects graph, is contained within another one (see examples bellow).

NPM version Build Status

Usage

Browser

<script src="chai.js"></script>
<script src="chai-shallow-deep-equal.js"></script>

Node

var chai = require('chai');
chai.use(require('chai-shallow-deep-equal'));

Assertions

ShallowDeepEqual is available for all chai assertion styles:

var a = {name: 'Michel', language: 'javascript'};
var b = {name: 'Michel'};

a.should.shallowDeepEqual(b);
expect(a).to.shallowDeepEqual(b);
assert.shallowDeepEqual(a, b);

Example

assert.shallowDeepEqual({name: 'Michel'}, {name: 'Michel', language: 'javascript'}); // true

assert.shallowDeepEqual({
  name: 'Michel',
  tags: [
    'developer'
  ]},
  {
  name: 'Michel',
  language: 'javascript',
  tags: [
    'developer',
    'gamer'
  ]}); // true
  
assert.shallowDeepEqual({
  length: 2,
  0: {color: 'red'},
  1: {brand: 'samsung'},
  },
  [
    {brand: 'apple', color: 'red'},
    {brand: 'samsung', color: 'blue'},
  ]); // true