Socket
Socket
Sign inDemoInstall

chai-shallow-deep-equal

Package Overview
Dependencies
7
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    chai-shallow-deep-equal

Shallow deep equal assertion for chai


Version published
Maintainers
1
Install size
14.7 kB
Created

Readme

Source

chai-shallow-deep-equal

Will shallowly perform a deep equal assertion. In other terms is consist 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', language: 'javascript'}, {name: 'Michel'}); // true

assert.shallowDeepEqual({
  name: 'Michel',
  language: 'javascript',
  tags: [
    'developer',
    'gamer'
  ]},
  {
  name: 'Michel',
  tags: [
    'developer'
  ]}); // true

assert.shallowDeepEqual([
    {brand: 'apple', color: 'red'},
    {brand: 'samsung', color: 'blue'},
  ],
  {
  length: 2,
  0: {color: 'red'},
  1: {brand: 'samsung'},
  }); // true

assert.shallowDeepEqual({
  name: 'Michel',
  age: undefined
  },
  {
  name: 'Michel',
  age: 37
  }); // false (age should not be defined)

Keywords

FAQs

Last updated on 25 Feb 2015

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc