forked from thedersen/backbone.validation
/
errorMessages.js
61 lines (50 loc) · 1.77 KB
/
errorMessages.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
buster.testCase("Specifying error messages", {
setUp: function() {
this.model = new Backbone.Model();
this.view = new Backbone.View({model: this.model});
this.invalid = this.spy();
Backbone.Validation.bind(this.view, {
invalid: this.invalid
});
},
"per validator": {
setUp: function() {
this.model.validation = {
email: [{
required: true,
msg: 'required'
},{
pattern: 'email',
msg: 'pattern'
}]
};
},
"and violating first validator returns msg specified for first validator": function() {
this.model.set({email: ''});
assert.calledWith(this.invalid, this.view, 'email', 'required');
},
"and violating second validator returns msg specified for second validator": function() {
this.model.set({email: 'a'});
assert.calledWith(this.invalid, this.view, 'email', 'pattern');
}
},
"per attribute": {
setUp: function() {
this.model.validation = {
email: {
required: true,
pattern: 'email',
msg: 'error'
}
};
},
"and violating first validator returns msg specified for attribute": function() {
this.model.set({email: ''});
assert.calledWith(this.invalid, this.view, 'email', 'error');
},
"and violating second validator returns msg specified for attribute": function() {
this.model.set({email: 'a'});
assert.calledWith(this.invalid, this.view, 'email', 'error');
}
}
});