Skip to content

Commit

Permalink
Merge pull request #182 from rocjs/fix/one-of-regexp
Browse files Browse the repository at this point in the history
Fixed a problem when oneOf was used together with a RegExp validator
  • Loading branch information
dlmr committed Jun 15, 2017
2 parents 0de8db5 + 82f4342 commit 5af65e9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/validation/validators/oneOf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import convert from '../../converters/convert';
import createInfoObject from '../helpers/createInfoObject';
import getInfoObject from '../helpers/getInfoObject';
import isValid from '../helpers/isValid';

/**
Expand Down Expand Up @@ -36,7 +37,7 @@ export default function oneOf(...validators) {
if (result === true) {
return true;
}
invalid.push(validator(null, true).type || 'Unknown type');
invalid.push(getInfoObject(validator).type || 'Unknown type');
}

/* eslint-disable prefer-template */
Expand Down
4 changes: 2 additions & 2 deletions test/validation/validators/oneOf.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ describe('validators', () => {
});

it('should return error if value is invalid', () => {
expect(oneOf(isInteger, isBoolean)('true'))
.toEqual('Was not any of the possible types:\n\nInteger\nBoolean');
expect(oneOf(/a/, isInteger, isBoolean)('true'))
.toEqual('Was not any of the possible types:\n\n/a/\nInteger\nBoolean');
});

it('should validate correctly', () => {
Expand Down

0 comments on commit 5af65e9

Please sign in to comment.