forked from Meteor-Community-Packages/meteor-simple-schema
-
Notifications
You must be signed in to change notification settings - Fork 2
/
validation-error-tests.js
39 lines (34 loc) · 1.05 KB
/
validation-error-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Tinytest.add('SimpleSchema - ValidationErrors', function (test) {
var schema = new SimpleSchema({
int: { type: Number },
string: { type: String },
});
function verify(error) {
test.equal(error.errorType, 'Meteor.Error');
test.equal(error.error, 'validation-error');
test.equal(error.details.length, 2);
test.equal(error.details[0].name, 'int');
test.equal(error.details[0].type, 'expectedNumber');
test.equal(error.details[1].name, 'string');
test.equal(error.details[1].type, 'required');
// In order for the message at the top of the stack trace to be useful,
// we set it to the first validation error message.
test.equal(error.reason, 'Int must be a number');
test.equal(error.message, 'Int must be a number [validation-error]');
}
try {
schema.validate({int: '5'});
} catch (error) {
verify(error);
}
try {
schema.validator()({int: '5'});
} catch (error) {
verify(error);
}
try {
schema.validator({clean: true})({int: '5'});
} catch (error) {
test.ok();
}
});