Skip to content

Commit

Permalink
fix condition, add tests for safe numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
paxa1887 committed Nov 6, 2018
1 parent b411b8e commit eb37582
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/types/number/index.js
Expand Up @@ -90,7 +90,7 @@ internals.Number = class extends Any {

if (isNumber) {
if (!this._flags.unsafe &&
(value >= Number.MAX_SAFE_INTEGER || value <= Number.MIN_SAFE_INTEGER)) {
(value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER)) {
result.errors = this.createError('number.unsafe', { value }, state, options);
}
}
Expand Down
12 changes: 12 additions & 0 deletions test/types/number.js
Expand Up @@ -1414,6 +1414,18 @@ describe('number', () => {
});
});

describe('safe', () => {

it('should accept safe numbers', () => {

const t = Joi.number();
Helper.validate(t, [
[Number.MAX_SAFE_INTEGER, true, null, Number.MAX_SAFE_INTEGER],
[Number.MIN_SAFE_INTEGER, true, null, Number.MIN_SAFE_INTEGER],
]);
});
});

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

it('throws when limit is not a number', () => {
Expand Down

0 comments on commit eb37582

Please sign in to comment.