Skip to content

Commit

Permalink
SF after changes on metal#293
Browse files Browse the repository at this point in the history
  • Loading branch information
diegonvs committed Nov 20, 2017
1 parent 4b3d3d7 commit 64eb77d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
12 changes: 7 additions & 5 deletions packages/metal-state/src/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -132,7 +132,7 @@ const validators = {
if (isInvalid(shapeResult)) {
return shapeResult;
}
if(isInvalid(valueResult)) {
if (isInvalid(valueResult)) {
return valueResult;
}
for (let key in shape) {
Expand Down Expand Up @@ -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}`
);
}

Expand Down Expand Up @@ -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);
}
}
Expand Down
40 changes: 20 additions & 20 deletions packages/metal-state/test/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 64eb77d

Please sign in to comment.