• Stars
    star
    108
  • Rank 321,259 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Improved deep equality testing for Node.js and the browser.

deep-eql

Improved deep equality testing for node and the browser.

build:? coverage:? dependencies:? devDependencies:?
Join the Slack chat Join the Gitter chat

What is Deep-Eql?

Deep Eql is a module which you can use to determine if two objects are "deeply" equal - that is, rather than having referential equality (a === b), this module checks an object's keys recursively, until it finds primitives to check for referential equality. For more on equality in JavaScript, read the comparison operators article on mdn.

As an example, take the following:

1 === 1 // These are primitives, they hold the same reference - they are strictly equal
1 == '1' // These are two different primitives, through type coercion they hold the same value - they are loosely equal
{ a: 1 } !== { a: 1 } // These are two different objects, they hold different references and so are not strictly equal - even though they hold the same values inside
{ a: 1 } != { a: 1 } // They have the same type, meaning loose equality performs the same check as strict equality - they are still not equal.

var deepEql = require("deep-eql");
deepEql({ a: 1 }, { a: 1 }) === true // deepEql can determine that they share the same keys and those keys share the same values, therefore they are deeply equal!

Installation

Node.js

deep-eql is available on npm.

$ npm install deep-eql

Usage

The primary export of deep-eql is function that can be given two objects to compare. It will always return a boolean which can be used to determine if two objects are deeply equal.

Rules

  • Strict equality for non-traversable nodes according to Object.is:
    • eql(NaN, NaN).should.be.true;
    • eql(-0, +0).should.be.false;
  • All own and inherited enumerable properties are considered:
    • eql(Object.create({ foo: { a: 1 } }), Object.create({ foo: { a: 1 } })).should.be.true;
    • eql(Object.create({ foo: { a: 1 } }), Object.create({ foo: { a: 2 } })).should.be.false;
  • When comparing Error objects, only name, message, and code properties are considered, regardless of enumerability:
    • eql(Error('foo'), Error('foo')).should.be.true;
    • eql(Error('foo'), Error('bar')).should.be.false;
    • eql(Error('foo'), TypeError('foo')).should.be.false;
    • eql(Object.assign(Error('foo'), { code: 42 }), Object.assign(Error('foo'), { code: 42 })).should.be.true;
    • eql(Object.assign(Error('foo'), { code: 42 }), Object.assign(Error('foo'), { code: 13 })).should.be.false;
    • eql(Object.assign(Error('foo'), { otherProp: 42 }), Object.assign(Error('foo'), { otherProp: 13 })).should.be.true;
  • Arguments are not Arrays:
    • eql([], arguments).should.be.false;
    • eql([], Array.prototype.slice.call(arguments)).should.be.true;

More Repositories

1

chai

BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
JavaScript
8,128
star
2

chai-as-promised

Extends Chai with assertions about promises.
JavaScript
1,421
star
3

sinon-chai

Extends Chai with assertions for the Sinon.JS mocking framework.
JavaScript
1,089
star
4

chai-http

HTTP Response assertions for the Chai Assertion Library.
JavaScript
634
star
5

chai-jquery

jQuery assertions for chai
JavaScript
372
star
6

chai-spies

Spies for Chai Assertion Library.
JavaScript
132
star
7

type-detect

Improved typeof detection for node.js and the browser.
JavaScript
130
star
8

chai-things

Chai support for assertions on array elements
CoffeeScript
104
star
9

chai-json-schema

Chai plugin for JSON Schema v4
JavaScript
75
star
10

chaijs.github.io

The chaijs.com website source code. Contributions welcome.
JavaScript
49
star
11

pathval

Object value retrieval given a string path
JavaScript
42
star
12

chai-fs

Chai assertions for Node.js filesystem
JavaScript
33
star
13

assertion-error

Error constructor for test and validation frameworks that implements standardized AssertionError specification.
TypeScript
25
star
14

chai-factories

Factories over fixtures. Chai Assertion Library.
JavaScript
23
star
15

loupe

Inspect utility for Node.js and browsers
JavaScript
21
star
16

chai-stats

Statistical and additional numerical assertions for the Chai Assertion Library.
JavaScript
16
star
17

check-error

Error comparison and information related utility for node and the browser
JavaScript
14
star
18

chai-change

Assert that a change you expected to happen, happened, with this chai plugin
JavaScript
14
star
19

get-func-name

Reliably get the name of a Function in a cross-browser compatible way.
JavaScript
12
star
20

simple-assert

Vanilla Assertions
JavaScript
7
star
21

chai-null

Null Object Pattern implementation for the Chai Assertion Library
JavaScript
5
star
22

chai-timers

Timers, stopwatches, and other time based assertions for the Chai Assertion Library.
JavaScript
5
star
23

guidelines

Guidelines for the Chaijs Organisation
1
star
24

plugin-use

A simple Event Emitter, tuned to be used as a plugin driver.
TypeScript
1
star