Skip to content

Commit

Permalink
Merge pull request #542 from blackflux/dev
Browse files Browse the repository at this point in the history
[Gally]: master <- dev
  • Loading branch information
simlu committed Apr 9, 2020
2 parents 844b8fc + 851f984 commit f6240bc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The following changes to the default joi behaviour were made:
- Every entry is required unless explicitly marked as [optional()](https://hapi.dev/family/joi/api/#anyoptional).
- Unknown object keys are not allowed unless explicitly market [unknown(true)](https://hapi.dev/family/joi/api/#objectunknownallow).
- Additional function `Joi.test(object, schema)` to check if a schema matches an object
- [boolean()](https://hapi.dev/family/joi/api/#boolean) automatically runs in [strict()](https://hapi.dev/family/joi/api/#anystrictisstrict) mode.
- [boolean()](https://hapi.dev/family/joi/api/#boolean) and [number()](https://hapi.dev/family/joi/api/#number) automatically runs in [strict()](https://hapi.dev/family/joi/api/#anystrictisstrict) mode.

## Usage

Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ module.exports = {
return schema.validate(object).error === undefined;
},
...Joi,
boolean: (...args) => Joi.boolean(...args).strict()
boolean: (...args) => Joi.boolean(...args).strict(),
number: (...args) => Joi.number(...args).strict()
};
12 changes: 12 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,16 @@ describe('Testing Strict Mode', () => {
expect(Joi.test(false, Joi.boolean())).to.equal(true);
});
});

describe('Testing Joi.number() is strict()', () => {
it('Testing string not allowed', () => {
expect(Joi.test('1', Joi.number())).to.equal(false);
expect(Joi.test('2', Joi.number())).to.equal(false);
});

it('Testing number allowed', () => {
expect(Joi.test(1, Joi.number())).to.equal(true);
expect(Joi.test(2, Joi.number())).to.equal(true);
});
});
});

0 comments on commit f6240bc

Please sign in to comment.