chai-exclude
Advanced tools
Comparing version 1.0.5 to 1.0.6
module.exports = (chai, utils) => { | ||
const assert = chai.assert | ||
const Assertion = chai.Assertion | ||
@@ -85,3 +86,3 @@ | ||
* | ||
* @param {any} arg | ||
* @param {any} arg | ||
* @returns {Boolean} | ||
@@ -111,6 +112,8 @@ */ | ||
return function (val) { | ||
const props = utils.flag(this, 'excludingProps') | ||
if (utils.flag(this, 'excluding')) { | ||
val = removeKeysFrom(val, utils.flag(this, 'excludingProps')) | ||
val = removeKeysFrom(val, props) | ||
} else if (utils.flag(this, 'excludingEvery')) { | ||
val = removeKeysFrom(val, utils.flag(this, 'excludingProps'), true) | ||
val = removeKeysFrom(val, props, true) | ||
} | ||
@@ -123,2 +126,16 @@ | ||
/** | ||
* Add a new method 'deepEqualExcluding' to 'chai.assert'. | ||
*/ | ||
utils.addMethod(assert, 'deepEqualExcluding', function (act, exp, props, msg) { | ||
new Assertion(act, msg).excluding(props).to.deep.equal(exp) | ||
}) | ||
/** | ||
* Add a new method `deepEqualExcludingEvery` to 'chai.assert'. | ||
*/ | ||
utils.addMethod(assert, 'deepEqualExcludingEvery', function (act, exp, props, msg) { | ||
new Assertion(act, msg).excludingEvery(props).to.deep.equal(exp) | ||
}) | ||
/** | ||
* Add a new method 'excluding' to the assertion library. | ||
@@ -140,2 +157,6 @@ */ | ||
if (!isArray(props)) { | ||
throw new Error('Excluding params should be either a string or an array') | ||
} | ||
this._obj = removeKeysFrom(obj, props) | ||
@@ -145,4 +166,2 @@ | ||
utils.flag(this, 'excludingProps', props) | ||
return this | ||
}) | ||
@@ -167,2 +186,6 @@ | ||
if (!isArray(props)) { | ||
throw new Error('Excluding params should be either a string or an array') | ||
} | ||
this._obj = removeKeysFrom(obj, props, true) | ||
@@ -172,4 +195,2 @@ | ||
utils.flag(this, 'excludingProps', props) | ||
return this | ||
}) | ||
@@ -176,0 +197,0 @@ |
{ | ||
"name": "chai-exclude", | ||
"version": "1.0.5", | ||
"description": "Exclude keys to compare from a deep equal operation with chai expect", | ||
"version": "1.0.6", | ||
"description": "Exclude keys to compare from a deep equal operation with chai expect and assert", | ||
"main": "lib/chai-exclude.js", | ||
@@ -16,2 +16,3 @@ "types": "lib/chai-exclude.d.ts", | ||
"chai", | ||
"assert", | ||
"expect", | ||
@@ -30,6 +31,6 @@ "exclude", | ||
"devDependencies": { | ||
"@types/chai": "^4.0.4", | ||
"@types/chai": "^4.1.2", | ||
"chai": "^4.1.2", | ||
"eslint": "^4.9.0", | ||
"eslint-config-standard": "^10.2.1", | ||
"eslint": "^4.17.0", | ||
"eslint-config-standard": "^11.0.0-beta.0", | ||
"eslint-plugin-import": "^2.8.0", | ||
@@ -39,4 +40,4 @@ "eslint-plugin-node": "^5.2.0", | ||
"eslint-plugin-standard": "^3.0.1", | ||
"mocha": "^4.0.1" | ||
"mocha": "^5.0.0" | ||
} | ||
} |
@@ -9,3 +9,3 @@ # chai-exclude | ||
Exclude keys to compare from a deep equal operation with chaijs [expect](http://chaijs.com/api/bdd/). | ||
Exclude keys to compare from a deep equal operation with chai [expect](http://chaijs.com/api/bdd/) or [assert](http://chaijs.com/api/assert/). | ||
@@ -32,3 +32,3 @@ ## Why? | ||
#### Require | ||
### Require | ||
@@ -42,3 +42,3 @@ ```js | ||
#### ES6 Import | ||
### ES6 Import | ||
@@ -52,3 +52,3 @@ ```js | ||
#### TypeScript | ||
### TypeScript | ||
@@ -72,2 +72,5 @@ ```js | ||
// 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' }) | ||
@@ -77,2 +80,5 @@ 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' }]) | ||
@@ -95,4 +101,7 @@ expect([{ a: 'a', b: 'b' }]).excluding('a').to.deep.equal([{ a: 'z', b: 'b' }]) | ||
// 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' }) | ||
expect(obj).excluding(['a', 'c']).to.deep.equal({ a: 'z', b: 'b' }) | ||
@@ -111,2 +120,5 @@ const array = [ | ||
// 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' }]) | ||
@@ -157,5 +169,7 @@ expect(array).excluding(['a', 'c']).to.deep.equal([{ a: 'z', b: 'b' }]) | ||
// 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) | ||
@@ -197,5 +211,7 @@ ``` | ||
// 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) | ||
@@ -202,0 +218,0 @@ ``` |
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
12268
171
217