chai-exclude
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -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) | ||
} |
{ | ||
"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: { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7825
86
166