From 7063b940a85fd55075d4b0db326e38a04e961d63 Mon Sep 17 00:00:00 2001 From: Johannes Loewe Date: Mon, 1 May 2017 21:59:08 +0200 Subject: [PATCH] assert interface: add nestedInclude and notNestedInclude --- lib/chai/interface/assert.js | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lib/chai/interface/assert.js b/lib/chai/interface/assert.js index d4a39ca..a90fbe4 100644 --- a/lib/chai/interface/assert.js +++ b/lib/chai/interface/assert.js @@ -1012,6 +1012,51 @@ module.exports = function (chai, util) { new Assertion(exp, msg, assert.notDeepInclude, true).not.deep.include(inc); }; + /** + * ### .nestedInclude + * + * Asserts that 'targetObject' includes 'nestedObject'. + * Enables the use of dot- and bracket-notation for referencing nested properties. + * '[]' and '.' in property names can be escaped using double backslashes. + * + * assert.nestedInclude({'.a': {'b': 'x'}}, {'\\.a.[b]': 'x'}); + * assert.nestedInclude({'a': {'[b]': 'x'}}, {'a.\\[b\\]': 'x'}); + * + * @name nestedInclude + * @param {Object} targetObject + * @param {Object} nestedObject + * @param {String} message + * @namespace Assert + * @api public + */ + + assert.nestedInclude = function (exp, inc, msg) { + new Assertion(exp, msg, assert.nestedInclude, true).nested.include(inc); + }; + + /** + * ### .notNestedInclude + * + * Asserts that 'targetObject' does not include 'nestedObject'. + * 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'}); + * + * + * @name notNestedInclude + * @param {Object} targetObject + * @param {Object} nestedObject + * @param {String} message + * @namespace Assert + * @api public + */ + + assert.notNestedInclude = function (exp, inc, msg) { + new Assertion(exp, msg, assert.notNestedInclude, true).not.nested.include(inc); + }; + /** * ### .match(value, regexp, [message]) *