diff --git a/src/__tests__/validator_config_tests.js b/src/__tests__/validator_config_tests.js index 87a6234..488de11 100644 --- a/src/__tests__/validator_config_tests.js +++ b/src/__tests__/validator_config_tests.js @@ -17,8 +17,18 @@ test('Validator should validate required rules', t => { }); t.deepEqual(result, { - noValue: { field: 'noValue', rule: 'required', value: null }, - notInObject: { field: 'notInObject', rule: 'required', value: undefined }, + noValue: { + field: 'noValue', + rule: 'required', + value: null, + config: { required: true }, + }, + notInObject: { + field: 'notInObject', + rule: 'required', + value: undefined, + config: { required: true }, + }, }); t.deepEqual(result, validator.getErrors()); }); diff --git a/src/__tests__/validator_tests.js b/src/__tests__/validator_tests.js index d5aa768..60927f6 100644 --- a/src/__tests__/validator_tests.js +++ b/src/__tests__/validator_tests.js @@ -39,7 +39,10 @@ test('validate should filter out valid values', t => { test('validateField should update errors', t => { const validator = new Validator({ a: { required: true }, b: { required: true } }); validator.validateField('a', null); - t.deepEqual(validator.errors, { a: { field: 'a', rule: 'required', value: null } }); + t.deepEqual( + validator.errors, + { a: { field: 'a', rule: 'required', value: null, config: { required: true } } }, + ); validator.validateField('a', 'c'); t.deepEqual(validator.errors, {}); }); @@ -49,7 +52,12 @@ test('validateField should return object with offending rule name', t => { t.deepEqual( validator.validateField('a', '2.0'), - { field: 'a', rule: 'numeric/integerOnly', value: '2.0' } + { + field: 'a', + rule: 'numeric.integerOnly', + value: '2.0', + config: { numeric: { integerOnly: true } }, + } ); }); diff --git a/src/rules/__tests__/array_tests.js b/src/rules/__tests__/arrayOf_tests.js similarity index 89% rename from src/rules/__tests__/array_tests.js rename to src/rules/__tests__/arrayOf_tests.js index 80d1667..44ec1ce 100644 --- a/src/rules/__tests__/array_tests.js +++ b/src/rules/__tests__/arrayOf_tests.js @@ -5,6 +5,6 @@ import { arrayOf } from '../'; test('rules.arrayOf should return array of validation errors', t => { t.deepEqual( arrayOf('elements', [{}], { name: { required: true } }), - [{ name: { rule: 'required', value: undefined, field: 'name' } }] + [{ name: { rule: 'required', value: undefined, field: 'name', config: { required: true } } }] ); }); diff --git a/src/validator.js b/src/validator.js index 681bd22..e2129f6 100644 --- a/src/validator.js +++ b/src/validator.js @@ -39,7 +39,7 @@ export default class Validator { ); if (result) { - result = { field, rule: result, value }; + result = { field, rule: result, value, config: this.config[field] }; this.errors = assign({}, this.errors, { [field]: result }); break; } else {