From 64eb77df55079a9ee5b26c7c89770dd1c562c332 Mon Sep 17 00:00:00 2001 From: Diego Nascimento Date: Mon, 20 Nov 2017 01:04:50 -0300 Subject: [PATCH] SF after changes on #293 --- packages/metal-state/src/validators.js | 12 ++++---- packages/metal-state/test/Config.js | 40 +++++++++++++------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/packages/metal-state/src/validators.js b/packages/metal-state/src/validators.js index be50722d..478f6bca 100644 --- a/packages/metal-state/src/validators.js +++ b/packages/metal-state/src/validators.js @@ -29,7 +29,7 @@ const validators = { */ arrayOf: function(validator) { const argsResult = validators.func(validator); - if(isInvalid(argsResult)){ + if (isInvalid(argsResult)) { return argsResult; } return maybe((value, name, context) => { @@ -64,7 +64,7 @@ const validators = { */ objectOf: function(validator) { const validatorResult = validators.func(validator); - if(isInvalid(validatorResult)){ + if (isInvalid(validatorResult)) { return validatorResult; } return maybe((value, name, context) => { @@ -132,7 +132,7 @@ const validators = { if (isInvalid(shapeResult)) { return shapeResult; } - if(isInvalid(valueResult)) { + if (isInvalid(valueResult)) { return valueResult; } for (let key in shape) { @@ -194,7 +194,7 @@ function composeError(error, name, context) { const location = parentName ? `Check render method of '${parentName}'.` : ''; return new Error( `Invalid state passed to '${name}'.` + -      ` ${error} Passed to '${compName}'. ${location}` + ` ${error} Passed to '${compName}'. ${location}` ); } @@ -250,7 +250,9 @@ function validateArrayItems(validator, value, name, context) { for (let i = 0; i < value.length; i++) { if (isInvalid(validator(value[i], name, context))) { let itemValidatorError = validator(value[i], name, context); - let errorMessage = `Validator for ${name}[${i}] says: "${itemValidatorError}"`; + let errorMessage = `Validator for ${name}[${i}] says: "${ + itemValidatorError + }"`; return composeError(errorMessage, name, context); } } diff --git a/packages/metal-state/test/Config.js b/packages/metal-state/test/Config.js index 4470bfed..60e77b1a 100644 --- a/packages/metal-state/test/Config.js +++ b/packages/metal-state/test/Config.js @@ -143,32 +143,32 @@ describe('Config', function() { assert.ok(config.config.validator(['one']) instanceof Error); }); - it('should return config with "arrayOf" validator inheriting "shapeOf" and "oneOf" from "validators"', function(){ - var shape = { + it('should return config with "arrayOf" validator inheriting "shapeOf" and "oneOf" from "validators"', function() { + let shape = { one: Config.bool().value(false), two: Config.string(), - three: Config.oneOf([ - 'propOne', - 'propTwo', - 'propThree' - ]).value('propOne'), - four: Config.number().required() + three: Config.oneOf(['propOne', 'propTwo', 'propThree']).value('propOne'), + four: Config.number().required(), }; - var configShape = Config.arrayOf(Config.shapeOf(shape)); + let configShape = Config.arrayOf(Config.shapeOf(shape)); assert.ok(core.isObject(configShape)); assert.ok(core.isFunction(configShape.config.validator)); - assert.ok(configShape.config.validator({ - one: false, - two: 30, - three: 'anything', - }) instanceof Error); + assert.ok( + configShape.config.validator({ + one: false, + two: 30, + three: 'anything', + }) instanceof Error + ); assert.ok(configShape.config.validator([1, 2]) instanceof Error); - assert.ok(configShape.config.validator({ - one: false, - two: 'is String!', - three: 'propOne', - four: 30 - })); + assert.ok( + configShape.config.validator({ + one: false, + two: 'is String!', + three: 'propOne', + four: 30, + }) + ); }); it('should return config with "bool" validator from "validators"', function() {