Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.map(email => validate(email, User.meta.props.email).firstError())
.map(error => assoc("email", error && error.message || null)), // TODO simplify?
.map(username => validate(username, User.meta.props.username).firstError())
.map(error => assoc("username", error && error.message || null)), // TODO simplify?
it('produces a valid type', () => {
const TextType = TextBuilder.getType();
expect(validate('banana', TextType).isValid()).to.be.true;
expect(validate('', TextType).isValid()).to.be.false;
expect(validate(42, TextType).isValid()).to.be.false;
expect(validate(null, TextType).isValid()).to.be.false;
expect(validate(undefined, TextType).isValid()).to.be.false;
expect(TextType.getValidationErrorMessage('banana')).to.equal(null);
expect(TextType.getValidationErrorMessage(null)).to.equal('Required');
});
});
it('produces a valid type', () => {
const TextType = TextBuilder.getType();
expect(validate('banana', TextType).isValid()).to.be.true;
expect(validate('', TextType).isValid()).to.be.false;
expect(validate(42, TextType).isValid()).to.be.false;
expect(validate(null, TextType).isValid()).to.be.false;
expect(validate(undefined, TextType).isValid()).to.be.false;
expect(TextType.getValidationErrorMessage('banana')).to.equal(null);
expect(TextType.getValidationErrorMessage(null)).to.equal('Required');
});
});
it('produces a valid type', () => {
const TextType = TextBuilder.getType();
expect(validate('banana', TextType).isValid()).to.be.true;
expect(validate('', TextType).isValid()).to.be.false;
expect(validate(42, TextType).isValid()).to.be.false;
expect(validate(null, TextType).isValid()).to.be.false;
expect(validate(undefined, TextType).isValid()).to.be.false;
expect(TextType.getValidationErrorMessage('banana')).to.equal(null);
expect(TextType.getValidationErrorMessage(null)).to.equal('Required');
});
});
it('produces a NumberType that validates correctly', () => {
const NumberType = NumberBuilder.getType();
expect(validate('banana', NumberType).isValid()).to.be.false;
expect(validate(42, NumberType).isValid()).to.be.true;
expect(NumberType.getValidationErrorMessage('banana')).to.equal('Please provide a number');
expect(NumberType.getValidationErrorMessage(42)).to.equal(null);
expect(NumberType.getValidationErrorMessage(null)).to.equal('Please provide a number');
});
});
it('produces a valid type', () => {
const TextType = TextBuilder.getType();
expect(validate('banana', TextType).isValid()).to.be.true;
expect(validate('', TextType).isValid()).to.be.false;
expect(validate(42, TextType).isValid()).to.be.false;
expect(validate(null, TextType).isValid()).to.be.false;
expect(validate(undefined, TextType).isValid()).to.be.false;
expect(TextType.getValidationErrorMessage('banana')).to.equal(null);
expect(TextType.getValidationErrorMessage(null)).to.equal('Required');
});
});
function validateValue(value, type, key) {
let result = validate(value, type);
let valid = result.isValid();
let errors = valid ? null : unflattenErrors(result.errors, key);
return {valid, errors};
}
getValue: function () {
var value = this.getTransformer().parse(this.state.value);
var result = t.validate(value, this.props.ctx.report.type, this.props.ctx.path);
this.setState({hasError: !result.isValid()});
return result;
},
getValue: function () {
var value = this.getTransformer().parse(this.state.value);
var result = t.validate(value, this.props.ctx.report.type, this.props.ctx.path);
this.setState({hasError: !result.isValid()});
return result;
},