10000 assert interface: add .deepOwnInclude and notdeepOwnInclude · chaijs/chai@40bb490 · GitHub
[go: up one dir, main page]

Skip to content

Commit 40bb490

Browse files
committed
assert interface: add .deepOwnInclude and notdeepOwnInclude
1 parent 97b6243 commit 40bb490

File tree

1 file changed

+71
-28
8000 lines changed

1 file changed

+71
-28
lines changed

lib/chai/interface/assert.js

Lines changed: 71 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,9 +1013,9 @@ module.exports = function (chai, util) {
10131013
};
10141014

10151015
/**
1016-
* ### .nestedInclude(targetObject, nestedObject, [message])
1016+
* ### .nestedInclude(object1, object2, [message])
10171017
*
1018-
* Asserts that 'targetObject' includes 'nestedObject'.
1018+
* Asserts that 'object1' includes 'object2'.
10191019
* Enables the use of dot- and bracket-notation for referencing nested
10201020
* properties.
10211021
* '[]' and '.' in property names can be escaped using double backslashes.
@@ -1024,8 +1024,8 @@ module.exports = function (chai, util) {
10241024
* assert.nestedInclude({'a': {'[b]': 'x'}}, {'a.\\[b\\]': 'x'});
10251025
*
10261026
* @name nestedInclude
1027-
* @param {Object} targetObject
1028-
* @param {Object} nestedObject
1027+
* @param {Object} object1
1028+
* @param {Object} object2
10291029
* @param {String} message
10301030
* @namespace Assert
10311031
* @api public
@@ -1036,20 +1036,19 @@ module.exports = function (chai, util) {
10361036
};
10371037

10381038
/**
1039-
* ### .notNestedInclude(targetObject, nestedObject, [message])
1039+
* ### .notNestedInclude(object1, object2, [message])
10401040
*
1041-
* Asserts that 'targetObject' does not include 'nestedObject'.
1041+
* Asserts that 'object1' does not include 'object2'.
10421042
* Enables the use of dot- and bracket-notation for referencing nested
10431043
* properties.
10441044
* '[]' and '.' in property names can be escaped using double backslashes.
10451045
*
1046-
* assert.notNestedInclude({'.a': {'b': 'x'}}, {'\\.a.[b]': 'y'});
1046+
* assert.notNestedInclude({'.a': {'b': 'x'}}, {'\\.a.b': 'y'});
10471047
* assert.notNestedInclude({'a': {'[b]': 'x'}}, {'a.\\[b\\]': 'y'});
10481048
*
1049-
*
10501049
* @name notNestedInclude
1051-
* @param {Object} targetObject
1052-
* @param {Object} nestedObject
1050+
* @param {Object} object1
1051+
* @param {Object} object2
10531052
* @param {String} message
10541053
* @namespace Assert
10551054
* @api public
@@ -1061,20 +1060,20 @@ module.exports = function (chai, util) {
10611060
};
10621061

10631062
/**
1064-
* ### .deepNestedInclude(targetObject, nestedObject, [message])
1063+
* ### .deepNestedInclude(object1, object2, [message])
10651064
*
1066-
* Asserts that 'targetObject' includes 'nestedObject' while checking for
1065+
* Asserts that 'object1' includes 'object2' while checking for
10671066
* deep equality.
10681067
* Enables the use of dot- and bracket-notation for referencing nested
10691068
* properties.
10701069
* '[]' and '.' in property names can be escaped using double backslashes.
10711070
*
1072-
* assert.deepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {x: 1}})
1071+
* assert.deepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {x: 1}});
10731072
* assert.deepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {x: 1}});
10741073
*
10751074
* @name deepNestedInclude
1076-
* @param {Object} targetObject
1077-
* @param {Object} nestedObject
1075+
* @param {Object} object1
1076+
* @param {Object} object2
10781077
* @param {String} message
10791078
* @namespace Assert
10801079
* @api public
@@ -1086,9 +1085,9 @@ module.exports = function (chai, util) {
10861085
};
10871086

10881087
/**
1089-
* ### .notDeepNestedInclude(targetObject, nestedObject, [message])
1088+
* ### .notDeepNestedInclude(object1, object2, [message])
10901089
*
1091-
* Asserts that 'targetObject' does not include 'nestedObject' while
1090+
* Asserts that 'object1' does not include 'object2' while
10921091
* checking for deep equality.
10931092
* Enables the use of dot- and bracket-notation for referencing nested
10941093
* properties.
@@ -1098,8 +1097,8 @@ module.exports = function (chai, util) {
10981097
* assert.notDeepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {y: 2}});
10991098
*
11001099
* @name notDeepNestedInclude
1101-
* @param {Object} targetObject
1102-
* @param {Object} nestedObject
1100+
* @param {Object} object1
1101+
* @param {Object} object2
11031102
* @param {String} message
11041103
* @namespace Assert
11051104
* @api public
@@ -1111,16 +1110,16 @@ module.exports = function (chai, util) {
11111110
};
11121111

11131112
/**
1114-
* ### .ownInclude(targetObject, objectToBeIncluded, [message])
1113+
* ### .ownInclude(object1, object2, [message])
11151114
*
1116-
* Asserts that 'targetObject' includes 'objectToBeIncluded' while
1115+
* Asserts that 'object1' includes 'object2' while
11171116
* ignoring inherited properties.
11181117
*
1119-
* assert.OwnInclude({ a: 1 }, { a: 1 });
1118+
* assert.ownInclude({ a: 1 }, { a: 1 });
11201119
*
11211120
* @name ownInclude
1122-
* @param {Object} targetObject
1123-
* @param {Object} objectToBeIncluded
1121+
* @param {Object} object1
1122+
* @param {Object} object2
11241123
* @param {String} message
11251124
* @namespace Assert
11261125
* @api public
@@ -1131,18 +1130,18 @@ module.exports = function (chai, util) {
11311130
};
11321131

11331132
/**
1134-
* ### .notOwnInclude(targetObject, objectToNotBeIncluded, [message])
1133+
* ### .notOwnInclude(object1, object2, [message])
11351134
*
1136-
* Asserts that 'targetObject' does not include 'objectToNotBeIncluded' while
1135+
* Asserts that 'object1' does not include 'object2' while
11371136
* ignoring inherited properties.
11381137
*
11391138
* Object.prototype.b = 2;
11401139
*
11411140
* assert.notOwnInclude({ a: 1 }, { b: 2 });
11421141
*
11431142
* @name notOwnInclude
1144-
* @param {Object} targetObject
1145-
* @param {Object} objectToNotBeIncluded
1143+
* @param {Object} object1
1144+
* @param {Object} object2
11461145
* @param {String} message
11471146
* @namespace Assert
11481147
* @api public
@@ -1152,6 +1151,50 @@ module.exports = function (chai, util) {
11521151
new Assertion(exp, msg, assert.notOwnInclude, true).not.own.include(inc);
11531152
};
11541153

1154+
/**
1155+
* ### .deepOwnInclude(object1, object2, [message])
1156+
*
1157+
* Asserts that 'object1' includes 'object2' while
1158+
* ignoring inherited properties.
1159+
* Deep equality is used.
1160+
*
1161+
* assert.deepOwnInclude({a: {b: 2}}, {a: {b: 2}});
1162+
*
1163+
* @name deepOwnInclude
1164+
* @param {Object} object1
1165+
* @param {Object} object2
1166+
* @param {String} message
1167+
* @namespace Assert
1168+
* @api public
1169+
*/
1170+
1171+
assert.deepOwnInclude = function(exp, inc, msg) {
1172+
new Assertion(exp, msg, assert.deepOwnInclude, true)
1173+
.deep.own.include(inc);
1174+
};
1175+
1176+
/**
1177+
* ### .notDeepOwnInclude(object1, object2, [message])
1178+
*
1179+
* Asserts that 'object1' does not include 'object2' while
1180+
* ignoring inherited properties.
1181+
* Deep equality is used.
1182+
*
1183+
* assert.notDeepOwnInclude({a: {b: 2}}, {a: {c: 3}});
1184+
*
1185+
* @name notDeepOwnInclude
1186+
* @param {Object} object1
1187+
* @param {Object} object2
1188+
* @param {String} message
1189+
* @namespace Assert
1190+
* @api public
1191+
*/
1192+
1193+
assert.notDeepOwnInclude = function(exp, inc, msg) {
1194+
new Assertion(exp, msg, assert.notDeepOwnInclude, true)
1195+
.not.deep.own.include(inc);
1196+
};
1197+
11551198
/**
11561199
* ### .match(value, regexp, [message])
11571200
*

0 commit comments

Comments
 (0)
0