Skip to content

Commit

Permalink
fix: Make arrayOf return null when there are no errors
Browse files Browse the repository at this point in the history
  • Loading branch information
relekang committed Nov 22, 2016
1 parent 13aef96 commit 031a27d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/rules/__tests__/arrayOf_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ describe('rules.arrayOf', () => {

expect(output).toEqual(expectedOutput);
});

it('should return null if everything is valid', () => {
expect(arrayOf('elements', [{}], { name: { numeric: { max: 2 } } }, validator)).toBe(null);
});
});
6 changes: 4 additions & 2 deletions src/rules/arrayOf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import { keys, map, omit } from 'lodash/fp';
import { isEmpty, flow, keys, map, omit, reject } from 'lodash/fp';
import type { ValidatorErrors, Validator, FieldConfig } from '../types';

export default function arrayOf(
Expand All @@ -11,5 +11,7 @@ export default function arrayOf(
const ruleOptions = omit('values')(options);
const validate = validator(ruleOptions);
const fields = keys(ruleOptions);
return map(item => validate(fields, item))(value);
const errors = map(item => validate(fields, item))(value);

return flow(reject(isEmpty), isEmpty)(errors) ? null : errors;
}

0 comments on commit 031a27d

Please sign in to comment.