Skip to content

Commit 7063b94

Browse files
committed
assert interface: add nestedInclude and notNestedInclude
1 parent 875057d commit 7063b94

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

lib/chai/interface/assert.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,51 @@ module.exports = function (chai, util) {
10121012
new Assertion(exp, msg, assert.notDeepInclude, true).not.deep.include(inc);
10131013
};
10141014

1015+
/**
1016+
* ### .nestedInclude
1017+
*
1018+
* Asserts that 'targetObject' includes 'nestedObject'.
1019+
* Enables the use of dot- and bracket-notation for referencing nested properties.
1020+
* '[]' and '.' in property names can be escaped using double backslashes.
1021+
*
1022+
* assert.nestedInclude({'.a': {'b': 'x'}}, {'\\.a.[b]': 'x'});
1023+
* assert.nestedInclude({'a': {'[b]': 'x'}}, {'a.\\[b\\]': 'x'});
1024+
*
1025+
* @name nestedInclude
1026+
* @param {Object} targetObject
1027+
* @param {Object} nestedObject
1028+
* @param {String} message
1029+
* @namespace Assert
1030+
* @api public
1031+
*/
1032+
1033+
assert.nestedInclude = function (exp, inc, msg) {
1034+
new Assertion(exp, msg, assert.nestedInclude, true).nested.include(inc);
1035+
};
1036+
1037+
/**
1038+
* ### .notNestedInclude
1039+
*
1040+
* Asserts that 'targetObject' does not include 'nestedObject'.
1041+
* Enables the use of dot- and bracket-notation for referencing nested properties.
1042+
* '[]' and '.' in property names can be escaped using double backslashes.
1043+
*
1044+
* assert.notNestedInclude({'.a': {'b': 'x'}}, {'\\.a.[b]': 'y'});
1045+
* assert.notNestedInclude({'a': {'[b]': 'x'}}, {'a.\\[b\\]': 'y'});
1046+
*
1047+
*
1048+
* @name notNestedInclude
1049+
* @param {Object} targetObject
1050+
* @param {Object} nestedObject
1051+
* @param {String} message
1052+
* @namespace Assert
1053+
* @api public
1054+
*/
1055+
1056+
assert.notNestedInclude = function (exp, inc, msg) {
1057+
new Assertion(exp, msg, assert.notNestedInclude, true).not.nested.include(inc);
1058+
};
1059+
10151060
/**
10161061
* ### .match(value, regexp, [message])
10171062
*

0 commit comments

Comments
 (0)