Skip to content

Commit

Permalink
Merge pull request #1354 from WesTyler/remove_example_validation
Browse files Browse the repository at this point in the history
Remove validation from .example
  • Loading branch information
Marsup committed Nov 12, 2017
2 parents a34deb3 + 06ae912 commit 61107b5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
2 changes: 0 additions & 2 deletions lib/types/any/index.js
Expand Up @@ -447,8 +447,6 @@ module.exports = internals.Any = class {

Hoek.assert(args.length === 1, 'Missing example');
const value = args[0];
const result = this._validate(value, null, internals.defaults);
Hoek.assert(!result.errors, 'Bad example:', result.errors && Errors.process(result.errors, value));

const obj = this.clone();
obj._examples.push(value);
Expand Down
9 changes: 4 additions & 5 deletions test/types/any.js
Expand Up @@ -1178,12 +1178,11 @@ describe('any', () => {
}).to.throw('Missing example');
});

it('throws when example fails own rules', () => {
it('does not throw when example fails own rules', () => {

expect(() => {

Joi.valid(5, 6, 7).example(4);
}).to.throw('Bad example: "value" must be one of [5, 6, 7]');
const schema = Joi.valid(5, 6, 7).example(4);
expect(schema._examples).to.equal([4]);
expect(schema.describe().examples).to.equal([4]);
});
});

Expand Down

0 comments on commit 61107b5

Please sign in to comment.