All Projects → mesaugat → chai-exclude

mesaugat / chai-exclude

Licence: MIT license
Exclude keys to compare from a deep equal operation with chai expect or assert.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to chai-exclude

Public
Repository for wallaby.js questions and issues
Stars: ✭ 662 (+1906.06%)
Mutual labels:  mocha, tdd, bdd
Cracking The Coding Interview Javascript Solutions Ctci
Javascript solutions to Cracking the Coding Interview (CTCI)
Stars: ✭ 139 (+321.21%)
Mutual labels:  mocha, tdd, chai
Chakram
REST API test framework. BDD and exploits promises
Stars: ✭ 912 (+2663.64%)
Mutual labels:  mocha, bdd, chai
Ut
UT: C++20 μ(micro)/Unit Testing Framework
Stars: ✭ 507 (+1436.36%)
Mutual labels:  unit-testing, tdd, bdd
Redux Actions Assertions
Simplify testing of redux action and async action creators
Stars: ✭ 177 (+436.36%)
Mutual labels:  unit-testing, mocha, chai
Baretest
An extremely fast and simple JavaScript test runner.
Stars: ✭ 364 (+1003.03%)
Mutual labels:  mocha, tdd, bdd
Snap Shot It
Smarter snapshot utility for Mocha and BDD test runners + data-driven testing!
Stars: ✭ 138 (+318.18%)
Mutual labels:  mocha, tdd, bdd
Expect More
Curried Type Testing library, and Test Matchers for Jest
Stars: ✭ 124 (+275.76%)
Mutual labels:  tdd, bdd, assert
Nspec
A battle hardened testing framework for C# that's heavily inspired by Mocha and RSpec.
Stars: ✭ 242 (+633.33%)
Mutual labels:  mocha, tdd, bdd
Karma
Spectacular Test Runner for JavaScript
Stars: ✭ 11,591 (+35024.24%)
Mutual labels:  mocha, tdd, bdd
Jasmine Matchers
Write Beautiful Specs with Custom Matchers for Jest and Jasmine
Stars: ✭ 552 (+1572.73%)
Mutual labels:  unit-testing, tdd, bdd
Ava
Node.js test runner that lets you develop with confidence 🚀
Stars: ✭ 19,458 (+58863.64%)
Mutual labels:  unit-testing, tdd, assert
earl
☕ Ergonomic, modern and type-safe assertion library for TypeScript
Stars: ✭ 217 (+557.58%)
Mutual labels:  mocha, chai, assert
Mocha
☕️ simple, flexible, fun javascript test framework for node.js & the browser
Stars: ✭ 20,986 (+63493.94%)
Mutual labels:  mocha, tdd, bdd
mocha-cakes-2
A BDD plugin for Mocha testing framework
Stars: ✭ 44 (+33.33%)
Mutual labels:  mocha, tdd, bdd
Should Enzyme
Useful functions for testing React Components with Enzyme.
Stars: ✭ 41 (+24.24%)
Mutual labels:  mocha, tdd, bdd
Earl
☕ Ergonomic, modern and type-safe assertion library for TypeScript
Stars: ✭ 153 (+363.64%)
Mutual labels:  mocha, chai, assert
respect
RSpec inspired test framework for Reason/OCaml/Bucklescript.
Stars: ✭ 28 (-15.15%)
Mutual labels:  unit-testing, tdd, bdd
chai
BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
Stars: ✭ 7,842 (+23663.64%)
Mutual labels:  tdd, bdd, chai
Quixote
CSS unit and integration testing
Stars: ✭ 788 (+2287.88%)
Mutual labels:  unit-testing, tdd

chai-exclude

npm npm JavaScript Style Guide CI Status

Exclude keys to compare from a deep equal operation with chai expect or assert.

Why?

Sometimes you'll need to exclude object properties that generate unique values while doing a deep equal operation. This plugin makes it easier to remove those properties from comparison.

chaijs/chai#885

Works with both objects and array of objects with or without circular references.

Installation

npm install chai-exclude --save-dev
yarn add chai-exclude --dev

Usage

Require

const chai = require('chai');
const chaiExclude = require('chai-exclude');

chai.use(chaiExclude);

ES6 Import

import chai from 'chai';
import chaiExclude from 'chai-exclude';

chai.use(chaiExclude);

TypeScript

import * as chai from 'chai';
import chaiExclude from 'chai-exclude';

chai.use(chaiExclude);

// The typings for chai-exclude are included with the package itself.

Examples

All these examples are for JavaScript. If you are using TypeScript and assert, you'll need to deal with strict types. Take a look at the type definition.

a) excluding

  1. Excluding a top level property from an object
// Object
assert.deepEqualExcluding({ a: 'a', b: 'b' }, { b: 'b' }, 'a')
assert.deepEqualExcluding({ a: 'a', b: 'b' }, { a: 'z', b: 'b' }, 'a')

expect({ a: 'a', b: 'b' }).excluding('a').to.deep.equal({ b: 'b' })
expect({ a: 'a', b: 'b' }).excluding('a').to.deep.equal({ a: 'z', b: 'b' })

// Array
assert.deepEqualExcluding([{ a: 'a', b: 'b' }], [{ b: 'b' }], 'a')
assert.deepEqualExcluding([{ a: 'a', b: 'b' }], [{ a: 'z', b: 'b' }], 'a')

expect([{ a: 'a', b: 'b' }]).excluding('a').to.deep.equal([{ b: 'b' }])
expect([{ a: 'a', b: 'b' }]).excluding('a').to.deep.equal([{ a: 'z', b: 'b' }])
  1. Excluding multiple top level properties from an object
const obj = {
  a: 'a',
  b: 'b',
  c: {
    d: 'd',
    e: 'e'
  }
}

// Object
assert.deepEqualExcluding(obj, { b: 'b' }, ['a', 'c'])
assert.deepEqualExcluding(obj, { a: 'z', b: 'b' }, ['a', 'c'])

expect(obj).excluding(['a', 'c']).to.deep.equal({ b: 'b' })
expect(obj).excluding(['a', 'c']).to.deep.equal({ a: 'z', b: 'b' })

const array = [
  {
    a: 'a',
    b: 'b',
    c: {
      d: 'd',
      e: 'e'
    }
  }
]

// Array
assert.deepEqualExcluding(array, [{ b: 'b' }], ['a', 'c'])
assert.deepEqualExcluding(array, [{ a: 'z', b: 'b' }], ['a', 'c'])

expect(array).excluding(['a', 'c']).to.deep.equal([{ b: 'b' }])
expect(array).excluding(['a', 'c']).to.deep.equal([{ a: 'z', b: 'b' }])

b) excludingEvery

  1. Excluding every property in a deeply nested object
const actualObj = {
  a: 'a',
  b: 'b',
  c: {
    a: 'a',
    b: {
      a: 'a',
      d: {
        a: 'a',
        b: 'b',
        d: null
      }
    }
  },
  d: ['a', 'c']
}

const actualArray = [actualObj]

const expectedObj = {
  a: 'z',     // a is excluded from comparison
  b: 'b',
  c: {
    b: {
      d: {
        b: 'b',
        d: null
      }
    }
  },
  d: ['a', 'c']
}

const expectedArray = [expectedObj]

// Object
assert.deepEqualExcludingEvery(actualObj, expectedObj, 'a')
expect(actualObj).excludingEvery('a').to.deep.equal(expectedObj)

// Array
assert.deepEqualExcludingEvery(actualArray, expectedArray, 'a')
expect(actualArray).excludingEvery('a').to.deep.equal(expectedArray)
  1. Excluding multiple properties in a deeply nested object
const actualObj = {
  a: 'a',
  b: 'b',
  c: {
    a: 'a',
    b: {
      a: 'a',
      d: {
        a: 'a',
        b: 'b',
        d: null
      }
    }
  },
  d: ['a', 'c']
}

const actualArray = [actualObj]

const expectedObj = {
  b: 'b',
  c: {
    b: {
    }
  }
}

const expectedArray = [expectedObj]

// Object
assert.deepEqualExcludingEvery(actualObj, expectedObj, ['a', 'd'])
expect(actualObj).excludingEvery(['a', 'd']).to.deep.equal(expectedObj)

// Array
assert.deepEqualExcludingEvery(actualArray, expectedArray, ['a', 'd'])
expect(actualArray).excludingEvery(['a', 'd']).to.deep.equal(expectedArray)

Contributing

Contributions are welcome. If you have any questions create an issue here.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].