8000 assert interface: add .ownInclude and .notOwnInclude · chaijs/chai@97b6243 · GitHub
[go: up one dir, main page]

Skip to content

Commit 97b6243

Browse files
committed
assert interface: add .ownInclude and .notOwnInclude
1 parent 24d7fa3 commit 97b6243

File tree

2 files changed

+70
-19
lines changed

2 files changed

+70
-19
lines changed

lib/chai/interface/assert.js

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

10151015
/**
1016-
* ### .nestedInclude(targetObj, nestedObject, [msg])
1016+
* ### .nestedInclude(targetObject, nestedObject, [message])
10171017
*
10181018
* Asserts that 'targetObject' includes 'nestedObject'.
1019-
* Enables the use of dot- and bracket-notation for referencing nested properties.
1019+
* Enables the use of dot- and bracket-notation for referencing nested
1020+
* properties.
10201021
* '[]' and '.' in property names can be escaped using double backslashes.
10211022
*
10221023
* assert.nestedInclude({'.a': {'b': 'x'}}, {'\\.a.[b]': 'x'});
@@ -1035,10 +1036,11 @@ module.exports = function (chai, util) {
10351036
};
10361037

10371038
/**
1038-
* ### .notNestedInclude(targetObj, nestedObj, [msg])
1039+
* ### .notNestedInclude(targetObject, nestedObject, [message])
10391040
*
10401041
* Asserts that 'targetObject' does not include 'nestedObject'.
1041-
* Enables the use of dot- and bracket-notation for referencing nested properties.
1042+
* Enables the use of dot- and bracket-notation for referencing nested
1043+
* properties.
10421044
* '[]' and '.' in property names can be escaped using double backslashes.
10431045
*
10441046
* assert.notNestedInclude({'.a': {'b': 'x'}}, {'\\.a.[b]': 'y'});
@@ -1054,18 +1056,21 @@ module.exports = function (chai, util) {
10541056
*/
10551057

10561058
assert.notNestedInclude = function (exp, inc, msg) {
1057-
new Assertion(exp, msg, assert.notNestedInclude, true).not.nested.include(inc);
1059+
new Assertion(exp, msg, assert.notNestedInclude, true)
1060+
.not.nested.include(inc);
10581061
};
10591062

10601063
/**
1061-
* ### .deepNestedInclude(targetObject, nestedObject, [msg])
1064+
* ### .deepNestedInclude(targetObject, nestedObject, [message])
10621065
*
1063-
* Asserts that 'targetObj' includes 'nestedObject' while checking for deep equality.
1064-
* Enables the user of dot- and bracket-notation for referencing nested properties.
1066+
* Asserts that 'targetObject' includes 'nestedObject' while checking for
1067+
* deep equality.
1068+
* Enables the use of dot- and bracket-notation for referencing nested
1069+
* properties.
10651070
* '[]' and '.' in property names can be escaped using double backslashes.
10661071
*
1067-
* assert.deepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {x: 1}})
1068-
* assert.deepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {x: 1}});
1072+
* assert.deepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {x: 1}})
1073+
* assert.deepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {x: 1}});
10691074
*
10701075
* @name deepNestedInclude
10711076
* @param {Object} targetObject
@@ -1076,18 +1081,21 @@ module.exports = function (chai, util) {
10761081
*/
10771082

10781083
assert.deepNestedInclude = function(exp, inc, msg) {
1079-
new Assertion(exp, msg, assert.deepNestedInclude, true).deep.nested.include(inc);
1084+
new Assertion(exp, msg, assert.deepNestedInclude, true)
1085+
.deep.nested.include(inc);
10801086
};
10811087

10821088
/**
1083-
* ### .notDeepNestedInclude(targetObject, nestedObject, [msg])
1089+
* ### .notDeepNestedInclude(targetObject, nestedObject, [message])
10841090
*
1085-
* Asserts that 'targetObj' does not include 'nestedObject' while checking for deep equality.
1086-
* Enables the user of dot- and bracket-notation for referencing nested properties.
1091+
* Asserts that 'targetObject' does not include 'nestedObject' while
1092+
* checking for deep equality.
1093+
* Enables the use of dot- and bracket-notation for referencing nested
1094+
* properties.
10871095
* '[]' and '.' in property names can be escaped using double backslashes.
10881096
*
1089-
* assert.notDeepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {y: 1}})
1090-
* assert.notDeepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {y: 2}});
1097+
* assert.notDeepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {y: 1}})
1098+
* assert.notDeepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {y: 2}});
10911099
*
10921100
* @name notDeepNestedInclude
10931101
* @param {Object} targetObject
@@ -1098,7 +1106,50 @@ module.exports = function (chai, util) {
10981106
*/
10991107

11001108
assert.notDeepNestedInclude = function(exp, inc, msg) {
1101-
new Assertion(exp, msg, assert.notDeepNestedInclude, true).not.deep.nested.include(inc);
1109+
new Assertion(exp, msg, assert.notDeepNestedInclude, true)
1110+
.not.deep.nested.include(inc);
1111+
};
1112+
1113+
/**
1114+
* ### .ownInclude(targetObject, objectToBeIncluded, [message])
1115+
*
1116+
* Asserts that 'targetObject' includes 'objectToBeIncluded' while
1117+
* ignoring inherited properties.
1118+
*
1119+
* assert.OwnInclude({ a: 1 }, { a: 1 });
1120+
*
1121+
* @name ownInclude
1122+
* @param {Object} targetObject
1123+
* @param {Object} objectToBeIncluded
1124+
* @param {String} message
1125+
* @namespace Assert
1126+
* @api public
1127+
*/
1128+
1129+
assert.ownInclude = function(exp, inc, msg) {
1130+
new Assertion(exp, msg, assert.ownInclude, true).own.include(inc);
B41A
1131+
};
1132+
1133+
/**
1134+
* ### .notOwnInclude(targetObject, objectToNotBeIncluded, [message])
1135+
*
1136+
* Asserts that 'targetObject' does not include 'objectToNotBeIncluded' while
1137+
* ignoring inherited properties.
1138+
*
1139+
* Object.prototype.b = 2;
1140+
*
1141+
* assert.notOwnInclude({ a: 1 }, { b: 2 });
1142+
*
1143+
* @name notOwnInclude
1144+
* @param {Object} targetObject
1145+
* @param {Object} objectToNotBeIncluded
1146+
* @param {String} message
1147+
* @namespace Assert
1148+
* @api public
1149+
*/
1150+
1151+
assert.notOwnInclude = function(exp, inc, msg) {
1152+
new Assertion(exp, msg, assert.notOwnInclude, true).not.own.include(inc);
11021153
};
11031154

11041155
/**

test/assert.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ describe('assert', function () {
812812
}, "blah: expected { a: 1 } to have own property 'a' of 3, but got 1");
813813

814814
err(function () {
815-
assert.ownInclude({a: 1}, 'blah', {a: 3});
815+
assert.ownInclude({a: 1}, {a: 3}, 'blah');
816816
}, "blah: expected { a: 1 } to have own property 'a' of 3, but got 1");
817817

818818
err(function () {
@@ -834,7 +834,7 @@ describe('assert', function () {
834834
}, "blah: expected { a: { b: 2 } } to have deep own property 'a' of { c: 3 }, but got { b: 2 }");
835835

836836
err(function () {
837-
assert.deepOwnInclude({a: {b: 2}}, 'blah', {a: {c: 3}});
837+
assert.deepOwnInclude({a: {b: 2}}, {a: {c: 3}}, 'blah');
838838
}, "blah: expected { a: { b: 2 } } to have deep own property 'a' of { c: 3 }, but got { b: 2 }");
839839

840840
err(function () {

0 commit comments

Comments
 (0)
0