- Source:
Namespaces
Methods
(static) addTest(obj, name)
- Source:
Used to add custom tests.
Example
var test = {
expects: false,
message: '{title} did not pass the test.',
validate: function(value) {
return this.strength(value);
},
};
approve.addTest(test, 'test_name');
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object | The test object to add. |
name |
String | The name of the test. |
Returns:
void
(static) value(value, rules) → {Object}
- Source:
Executes the tests based on given rules to validate a given value.
Returns an object with at least two properties:
Returns an object with at least two properties:
approved
: Boolean - true
if test succeeded, otherwise false
.errors
: Array of String - holds a list of formatted errors.
Example
var result = approve.value('some value', {test: constraints});
if (result.approved) {
// Value is approved - do something
} else {
// Do something with the errors
result.each(function(error) {
console.log(error);
});
}
Parameters:
Name | Type | Description |
---|---|---|
value |
Object | The value to test against the rules. |
rules |
Object | The constraints for the value being tested. |
Returns:
The object containing the result of the tests performed.
- Type
- Object