Skip to content

Commit

Permalink
assert interface: add .deepOwnInclude and notdeepOwnInclude
Browse files Browse the repository at this point in the history
  • Loading branch information
zetamorph committed May 4, 2017
1 parent 97b6243 commit 40bb490
Showing 1 changed file with 71 additions and 28 deletions.
99 changes: 71 additions & 28 deletions lib/chai/interface/assert.js
Expand Up @@ -1013,9 +1013,9 @@ module.exports = function (chai, util) {
};

/**
* ### .nestedInclude(targetObject, nestedObject, [message])
* ### .nestedInclude(object1, object2, [message])
*
* Asserts that 'targetObject' includes 'nestedObject'.
* Asserts that 'object1' includes 'object2'.
* Enables the use of dot- and bracket-notation for referencing nested
* properties.
* '[]' and '.' in property names can be escaped using double backslashes.
Expand All @@ -1024,8 +1024,8 @@ module.exports = function (chai, util) {
* assert.nestedInclude({'a': {'[b]': 'x'}}, {'a.\\[b\\]': 'x'});
*
* @name nestedInclude
* @param {Object} targetObject
* @param {Object} nestedObject
* @param {Object} object1
* @param {Object} object2
* @param {String} message
* @namespace Assert
* @api public
Expand All @@ -1036,20 +1036,19 @@ module.exports = function (chai, util) {
};

/**
* ### .notNestedInclude(targetObject, nestedObject, [message])
* ### .notNestedInclude(object1, object2, [message])
*
* Asserts that 'targetObject' does not include 'nestedObject'.
* Asserts that 'object1' does not include 'object2'.
* Enables the use of dot- and bracket-notation for referencing nested
* properties.
* '[]' and '.' in property names can be escaped using double backslashes.
*
* assert.notNestedInclude({'.a': {'b': 'x'}}, {'\\.a.[b]': 'y'});
* assert.notNestedInclude({'.a': {'b': 'x'}}, {'\\.a.b': 'y'});
* assert.notNestedInclude({'a': {'[b]': 'x'}}, {'a.\\[b\\]': 'y'});
*
*
* @name notNestedInclude
* @param {Object} targetObject
* @param {Object} nestedObject
* @param {Object} object1
* @param {Object} object2
* @param {String} message
* @namespace Assert
* @api public
Expand All @@ -1061,20 +1060,20 @@ module.exports = function (chai, util) {
};

/**
* ### .deepNestedInclude(targetObject, nestedObject, [message])
* ### .deepNestedInclude(object1, object2, [message])
*
* Asserts that 'targetObject' includes 'nestedObject' while checking for
* Asserts that 'object1' includes 'object2' while checking for
* deep equality.
* Enables the use of dot- and bracket-notation for referencing nested
* properties.
* '[]' and '.' in property names can be escaped using double backslashes.
*
* assert.deepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {x: 1}})
* assert.deepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {x: 1}});
* assert.deepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {x: 1}});
*
* @name deepNestedInclude
* @param {Object} targetObject
* @param {Object} nestedObject
* @param {Object} object1
* @param {Object} object2
* @param {String} message
* @namespace Assert
* @api public
Expand All @@ -1086,9 +1085,9 @@ module.exports = function (chai, util) {
};

/**
* ### .notDeepNestedInclude(targetObject, nestedObject, [message])
* ### .notDeepNestedInclude(object1, object2, [message])
*
* Asserts that 'targetObject' does not include 'nestedObject' while
* Asserts that 'object1' does not include 'object2' while
* checking for deep equality.
* Enables the use of dot- and bracket-notation for referencing nested
* properties.
Expand All @@ -1098,8 +1097,8 @@ module.exports = function (chai, util) {
* assert.notDeepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {y: 2}});
*
* @name notDeepNestedInclude
* @param {Object} targetObject
* @param {Object} nestedObject
* @param {Object} object1
* @param {Object} object2
* @param {String} message
* @namespace Assert
* @api public
Expand All @@ -1111,16 +1110,16 @@ module.exports = function (chai, util) {
};

/**
* ### .ownInclude(targetObject, objectToBeIncluded, [message])
* ### .ownInclude(object1, object2, [message])
*
* Asserts that 'targetObject' includes 'objectToBeIncluded' while
* Asserts that 'object1' includes 'object2' while
* ignoring inherited properties.
*
* assert.OwnInclude({ a: 1 }, { a: 1 });
* assert.ownInclude({ a: 1 }, { a: 1 });
*
* @name ownInclude
* @param {Object} targetObject
* @param {Object} objectToBeIncluded
* @param {Object} object1
* @param {Object} object2
* @param {String} message
* @namespace Assert
* @api public
Expand All @@ -1131,18 +1130,18 @@ module.exports = function (chai, util) {
};

/**
* ### .notOwnInclude(targetObject, objectToNotBeIncluded, [message])
* ### .notOwnInclude(object1, object2, [message])
*
* Asserts that 'targetObject' does not include 'objectToNotBeIncluded' while
* Asserts that 'object1' does not include 'object2' while
* ignoring inherited properties.
*
* Object.prototype.b = 2;
*
* assert.notOwnInclude({ a: 1 }, { b: 2 });
*
* @name notOwnInclude
* @param {Object} targetObject
* @param {Object} objectToNotBeIncluded
* @param {Object} object1
* @param {Object} object2
* @param {String} message
* @namespace Assert
* @api public
Expand All @@ -1152,6 +1151,50 @@ module.exports = function (chai, util) {
new Assertion(exp, msg, assert.notOwnInclude, true).not.own.include(inc);
};

/**
* ### .deepOwnInclude(object1, object2, [message])
*
* Asserts that 'object1' includes 'object2' while
* ignoring inherited properties.
* Deep equality is used.
*
* assert.deepOwnInclude({a: {b: 2}}, {a: {b: 2}});
*
* @name deepOwnInclude
* @param {Object} object1
* @param {Object} object2
* @param {String} message
* @namespace Assert
* @api public
*/

assert.deepOwnInclude = function(exp, inc, msg) {
new Assertion(exp, msg, assert.deepOwnInclude, true)
.deep.own.include(inc);
};

/**
* ### .notDeepOwnInclude(object1, object2, [message])
*
* Asserts that 'object1' does not include 'object2' while
* ignoring inherited properties.
* Deep equality is used.
*
* assert.notDeepOwnInclude({a: {b: 2}}, {a: {c: 3}});
*
* @name notDeepOwnInclude
* @param {Object} object1
* @param {Object} object2
* @param {String} message
* @namespace Assert
* @api public
*/

assert.notDeepOwnInclude = function(exp, inc, msg) {
new Assertion(exp, msg, assert.notDeepOwnInclude, true)
.not.deep.own.include(inc);
};

/**
* ### .match(value, regexp, [message])
*
Expand Down

0 comments on commit 40bb490

Please sign in to comment.