Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chai-exclude

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chai-exclude - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

30

lib/chai-exclude.js

@@ -30,2 +30,22 @@ module.exports = (chai, utils) => {

/**
* Override of the standard assertEqual to also remove the keys from the
* other part of the equation.
*
* @param {Object} _super
* @returns {Function}
*/
function assertEqual (_super) {
return function (val) {
if (utils.type(val).toLowerCase() === 'object') {
if (utils.flag(this, 'excluding')) {
val = removeKeys(val, utils.flag(this, 'excludingProps'))
} else if (utils.flag(this, 'excludingEvery')) {
val = removeKeys(val, utils.flag(this, 'excludingProps'), true)
}
}
_super.apply(this, arguments)
}
}
Assertion.addMethod('excluding', function (props) {

@@ -45,2 +65,5 @@ utils.expectTypes(this, ['object'])

utils.flag(this, 'excluding', true)
utils.flag(this, 'excludingProps', props)
return this

@@ -63,4 +86,11 @@ })

utils.flag(this, 'excludingEvery', true)
utils.flag(this, 'excludingProps', props)
return this
})
Assertion.overwriteMethod('eq', assertEqual)
Assertion.overwriteMethod('equal', assertEqual)
Assertion.overwriteMethod('equals', assertEqual)
}

4

package.json
{
"name": "chai-exclude",
"version": "1.0.2",
"description": "Exclude keys before a deep equal operation with expect",
"version": "1.0.3",
"description": "Exclude keys to compare from a deep equal operation with chai expect",
"main": "lib/chai-exclude.js",

@@ -6,0 +6,0 @@ "types": "lib/chai-exclude.d.ts",

@@ -8,7 +8,7 @@ # chai-exclude

Exclude keys before a deep equal operation with chaijs [expect](http://chaijs.com/api/bdd/).
Exclude keys to compare from a deep equal operation with chaijs [expect](http://chaijs.com/api/bdd/).
## Why?
Sometimes you'll need to exclude object properties that generate unique values while doing a deep equal comparison. This plugin makes it easier to remove those top level properties before comparison.
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 before comparison.

@@ -62,6 +62,7 @@ https://github.com/chaijs/chai/issues/885

1. Excluding a property from an object
1. Excluding a top level property from an object
```js
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' })
```

@@ -82,2 +83,3 @@

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

@@ -108,2 +110,3 @@

const expected = {
a: 'z', // a is excluded from comparison
b: 'b',

@@ -110,0 +113,0 @@ c: {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc