Skip to content

Commit

Permalink
Merge pull request #1183 from danielo515/patch-1
Browse files Browse the repository at this point in the history
add forbiddenKeys method to object
  • Loading branch information
Marsup committed May 13, 2017
2 parents e2b5d49 + e73d0d9 commit dcc6f4c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,12 @@ internals.Object = class extends Any {
return this.applyFunctionToChildren(children, 'optional');
}

forbiddenKeys(children) {

children = Hoek.flatten(Array.prototype.slice.call(arguments));
return this.applyFunctionToChildren(children, 'forbidden');
}

rename(from, to, options) {

Hoek.assert(typeof from === 'string', 'Rename missing the from argument');
Expand Down
14 changes: 14 additions & 0 deletions test/any.js
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,20 @@ describe('any', () => {
], done);
});
});
describe('forbiddenKeys()', () => {

it('should set keys as forbidden', (done) => {

const schema = Joi.object({ a: Joi.number().required(), b: Joi.number().required() }).forbiddenKeys('a', 'b');
Helper.validate(schema, [
[{}, true],
[{ a: undefined }, true],
[{ a: undefined, b: undefined }, true],
[{ a: 0 }, false, null, 'child "a" fails because ["a" is not allowed]'],
[{ b: 0 }, false, null, 'child "b" fails because ["b" is not allowed]']
], done);
});
});

describe('empty()', () => {

Expand Down

0 comments on commit dcc6f4c

Please sign in to comment.