Skip to content

Commit

Permalink
fix: min was not invalid for non-numbers; neither min nor max were te…
Browse files Browse the repository at this point in the history
…sting for that
  • Loading branch information
jeffhandley committed Dec 22, 2017
1 parent 2eb2eec commit 250bda3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/strickland/src/max.js
Expand Up @@ -31,8 +31,10 @@ export default function max(maxProp, validatorProps) {

if (isFalsyButNotZero(value)) {
// Empty values are always valid except with the required validator

} else if (typeof value !== 'number') {
isValid = false;

} else if (value > validationProps.max) {
isValid = false;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/strickland/src/min.js
Expand Up @@ -32,6 +32,9 @@ export default function min(minProp, validatorProps) {
if (isFalsyButNotZero(value)) {
// Empty values are always valid except with the required validator

} else if (typeof value !== 'number') {
isValid = false;

} else if (value < validationProps.min) {
isValid = false;
}
Expand Down
5 changes: 5 additions & 0 deletions packages/strickland/test/max.spec.js
Expand Up @@ -112,6 +112,11 @@ describe('max', () => {
const result = validate();
expect(result.isValid).toBe(true);
});

it('with a string value, it is not valid', () => {
const result = validate('A');
expect(result.isValid).toBe(false);
});
});

describe('with props passed into validation', () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/strickland/test/min.spec.js
Expand Up @@ -99,6 +99,11 @@ describe('min', () => {
const result = validate();
expect(result.isValid).toBe(true);
});

it('with a string value, it is not valid', () => {
const result = validate('A');
expect(result.isValid).toBe(false);
});
});

describe('with props passed into validation', () => {
Expand Down

0 comments on commit 250bda3

Please sign in to comment.