2016-12-26 01:09:24 +00:00
|
|
|
import 'package:angel_validate/angel_validate.dart';
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
2016-12-26 13:04:42 +00:00
|
|
|
final Validator emailSchema = new Validator({
|
2016-12-26 13:07:00 +00:00
|
|
|
'to': isEmail
|
2016-12-26 13:04:42 +00:00
|
|
|
}, customErrorMessages: {
|
|
|
|
'to': 'Hello, world!'
|
|
|
|
});
|
|
|
|
|
2016-12-26 01:09:24 +00:00
|
|
|
final Validator todoSchema = new Validator({
|
|
|
|
'id': [isInt, isPositive],
|
|
|
|
'text*': isString,
|
|
|
|
'completed*': isBool
|
|
|
|
}, defaultValues: {
|
|
|
|
'completed': false
|
|
|
|
});
|
|
|
|
|
|
|
|
main() {
|
2016-12-26 13:04:42 +00:00
|
|
|
test('custom error message', () {
|
|
|
|
var result = emailSchema.check({'to': 2});
|
|
|
|
|
|
|
|
expect(result.errors, isList);
|
|
|
|
expect(result.errors, hasLength(1));
|
|
|
|
expect(result.errors.first, equals('Hello, world!'));
|
|
|
|
});
|
|
|
|
|
2016-12-26 01:09:24 +00:00
|
|
|
test('todo', () {
|
|
|
|
expect(() {
|
|
|
|
todoSchema
|
|
|
|
.enforce({'id': 'fool', 'text': 'Hello, world!', 'completed': 4});
|
|
|
|
}, throwsA(new isInstanceOf<ValidationException>()));
|
|
|
|
});
|
|
|
|
}
|