Skip to content

Commit

Permalink
test: add assert.nestedInclude and assert.notNestedInclude
Browse files Browse the repository at this point in the history
  • Loading branch information
zetamorph committed May 4, 2017
1 parent 850bd7e commit 479e4c4
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,33 @@ describe('assert', function () {
}, "expected { foo: { a: 1 }, bar: { b: 2 } } to not have deep property 'foo' of { a: 1 }");
});

it('nestedInclude and notNestedInclude', function() {
assert.nestedInclude({a: {b: ['x', 'y']}}, {'a.b[1]': 'y'});
assert.notNestedInclude({a: {b: ['x', 'y']}}, {'a.b[1]': 'x'});
assert.notNestedInclude({a: {b: ['x', 'y']}}, {'a.c': 'y'});

assert.notNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {x: 1}});

assert.nestedInclude({'.a': {'[b]': 'x'}}, {'\\.a.\\[b\\]': 'x'});
assert.notNestedInclude({'.a': {'[b]': 'x'}}, {'\\.a.\\[b\\]': 'y'});

err(function () {
assert.nestedInclude({a: {b: ['x', 'y']}}, {'a.b[1]': 'x'}, 'blah');
}, "blah: expected { a: { b: [ 'x', 'y' ] } } to have nested property 'a.b[1]' of 'x', but got 'y'");

err(function () {
assert.nestedInclude({a: {b: ['x', 'y']}}, 'blah', {'a.b[1]': 'x'});
}, "blah: expected { a: { b: [ 'x', 'y' ] } } to have nested property 'a.b[1]' of 'x', but got 'y'");

err(function () {
assert.nestedInclude({a: {b: ['x', 'y']}}, {'a.c': 'y'});
}, "expected { a: { b: [ 'x', 'y' ] } } to have nested property 'a.c'");

err(function () {
assert.nestedInclude({a: {b: ['x', 'y']}}, {'a.b[1]': 'y'});
}, "expected { a: { b: [ 'x', 'y' ] } } to not have nested property 'a.b[1]' of 'y'");
});

it('keys(array|Object|arguments)', function(){
assert.hasAllKeys({ foo: 1 }, [ 'foo' ]);
assert.hasAllKeys({ foo: 1, bar: 2 }, [ 'foo', 'bar' ]);
Expand Down

0 comments on commit 479e4c4

Please sign in to comment.