From 889b489fe99fc9d1191692b93b803a06e8edc0aa Mon Sep 17 00:00:00 2001 From: Johannes Loewe Date: Mon, 1 May 2017 18:46:18 +0200 Subject: [PATCH] test: add assert.deepNestedInclude and assert.notDeepNestedInclude --- test/assert.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/assert.js b/test/assert.js index a25db7927..97bd195ea 100644 --- a/test/assert.js +++ b/test/assert.js @@ -775,6 +775,31 @@ describe('assert', function () { }, "expected { a: { b: [ 'x', 'y' ] } } to not have nested property 'a.b[1]' of 'y'"); }); + it('deepNestedInclude and notDeepNestedInclude', function() { + assert.deepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {x: 1}}); + assert.notDeepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {y: 2}}); + assert.notDeepNestedInclude({a: {b: [{x: 1}]}}, {'a.c': {x: 1}}); + + assert.deepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {x: 1}}); + assert.notDeepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {y: 2}}); + + err(function () { + assert.deepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {y: 2}}, 'blah'); + }, "blah: expected { a: { b: [ [Object] ] } } to have deep nested property 'a.b[0]' of { y: 2 }, but got { x: 1 }"); + + err(function () { + assert.deepNestedInclude({a: {b: [{x: 1}]}}, 'blah', {'a.b[0]': {y: 2}}); + }, "blah: expected { a: { b: [ [Object] ] } } to have deep nested property 'a.b[0]' of { y: 2 }, but got { x: 1 }"); + + err(function () { + assert.deepNestedInclude({a: {b: [{x: 1}]}}, {'a.c': {x: 1}}); + }, "expected { a: { b: [ [Object] ] } } to have deep nested property 'a.c'"); + + err(function () { + assert.notDeepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {x: 1}}); + }, "expected { a: { b: [ [Object] ] } } to not have deep nested property 'a.b[0]' of { x: 1 }"); + }); + it('ownInclude and notOwnInclude', function() { assert.ownInclude({a: 1}, {a: 1}); assert.notOwnInclude({a: 1}, {a: 3});