Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// neither |message| nor |messages| present
var no_messages = {
validation : [ "trim", "notEmpty", "integer" ]
};
asserts.throws( function() { v.validateField( no_messages, "" ); },
"notEmpty",
"notEmpty should throw its name" );
asserts.throws( function() { v.validateField( no_messages, " " ); },
"notEmpty",
"notEmpty should throw its name" );
asserts.throws( function() { v.validateField( no_messages, "foo" ); },
"integer",
"integer should throw its name" );
// default messages
Validation.messages.test = {
"notEmpty" : "default for notEmpty",
"integer" : "default for integer"
};
asserts.throws( function() { v.validateField( no_messages, "" ); },
"default for notEmpty",
"notEmpty should throw it's default message" );
asserts.throws( function() { v.validateField( no_messages, " " ); },
"default for notEmpty",
"notEmpty should throw it's default message" );
asserts.throws( function() { v.validateField( no_messages, "foo" ); },
"default for integer",
"integer should throw it's default message" );
}
exports.test_ValidateFieldMessages = function () {
Validation.messages.test = {};
var v = new Validation( undefined, "test" ); // language is "test" for error messages
// |message| present
var one_message = {
validation : [ "trim", "notEmpty", "integer" ],
message : "one message"
};
asserts.throws( function() { v.validateField( one_message, "" ); },
"one message",
"All errors should throw single message" );
asserts.throws( function() { v.validateField( one_message, " " ); },
"one message",
"All errors should throw single message" );
asserts.throws( function() { v.validateField( one_message, "foo" ); },
"one message",
"All errors should throw single message" );