How to use the juice/validation.Validation function in juice

To help you get started, we’ve selected a few juice examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ashb / juice / test / validation.t.js View on Github external
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" );
github ashb / juice / test / validation.t.js View on Github external
exports.test_ValidateFieldChaining = function () {
  var v = new Validation();
  var chained = { validation : [ "trim", "notEmpty", "integer", "positive" ] };
  asserts.throws( function() { v.validateField( chained, "" ); }, "Empty field should throw error" );
  asserts.throws( function() { v.validateField( chained, "  " ); }, "Whitespace only should throw error" );
  asserts.throws( function() { v.validateField( chained, "foo" ); }, "Non integer should throw error" );
  asserts.throws( function() { v.validateField( chained, "-123" ); }, "Negative integer should throw an error" );
  asserts.same( v.validateField( chained, "123" ), 123, "Positive integer should be parsed into a number" );
  asserts.same( v.validateField( chained, " 123 " ), 123, "Positive integer with trimmable whitespace should be parsed into a number" );
}