Skip to content

Commit d0c56e0

Browse files
committed
Build: Run JSCS against tests
1 parent 56a2a18 commit d0c56e0

File tree

6 files changed

+214
-149
lines changed

6 files changed

+214
-149
lines changed

.jscsrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"requireMultipleVarDecl": "onevar",
1717
"disallowTrailingWhitespace": true,
1818
"validateQuoteMarks": "\"",
19+
"requireSpacesInsideArrayBrackets": "allButNested",
1920
"excludeFiles": [
2021
"node_modules/**",
2122
"dist/**"

test/error-placement.js

Lines changed: 80 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,36 @@ test( "elements() order", function() {
77
wrap: "li"
88
});
99

10-
deepEqual( v.elements().map( function() {
11-
return $( this ).attr( "id" );
12-
}).get(), ["order1", "order2", "order3", "order4", "order5", "order6"], "elements must be in document order" );
10+
deepEqual(
11+
v.elements().map( function() {
12+
return $( this ).attr( "id" );
13+
}).get(),
14+
[
15+
"order1",
16+
"order2",
17+
"order3",
18+
"order4",
19+
"order5",
20+
"order6"
21+
],
22+
"elements must be in document order"
23+
);
24+
1325
v.form();
14-
deepEqual( container.children().map( function() {
15-
return $( this ).attr( "id" );
16-
}).get(), ["order1-error", "order2-error", "order3-error", "order4-error", "order5-error", "order6-error"], "labels in error container must be in document order" );
26+
deepEqual(
27+
container.children().map( function() {
28+
return $( this ).attr( "id" );
29+
}).get(),
30+
[
31+
"order1-error",
32+
"order2-error",
33+
"order3-error",
34+
"order4-error",
35+
"order5-error",
36+
"order6-error"
37+
],
38+
"labels in error container must be in document order"
39+
);
1740
});
1841

1942
test( "error containers, simple", function() {
@@ -33,7 +56,21 @@ test( "error containers, simple", function() {
3356
equal( "", container.find( "h3" ).html() );
3457

3558
v.prepareForm();
36-
v.errorList = [{message:"bar", element: {name:"foo"}}, {message: "necessary", element: {name:"required"}}];
59+
v.errorList = [
60+
{
61+
message: "bar",
62+
element: {
63+
name: "foo"
64+
}
65+
},
66+
{
67+
message: "necessary",
68+
element: {
69+
name: "required"
70+
}
71+
}
72+
];
73+
3774
ok( !v.valid(), "form is not valid after adding errors manually" );
3875
v.showErrors();
3976
equal( container.find( ".error:not(input)" ).length, 2, "There should be two error labels" );
@@ -68,7 +105,22 @@ test( "error containers, with labelcontainer I", function() {
68105
equal( 0, labelcontainer.find( ".error:not(input)" ).length, "There should be no error labels in the labelcontainer" );
69106
equal( 0, labelcontainer.find( "li" ).length, "There should be no lis labels in the labelcontainer" );
70107

71-
v.errorList = [{message:"bar", element: {name:"foo"}}, {name: "required", message: "necessary", element: {name:"required"}}];
108+
v.errorList = [
109+
{
110+
message: "bar",
111+
element: {
112+
name: "foo"
113+
}
114+
},
115+
{
116+
name: "required",
117+
message: "necessary",
118+
element: {
119+
name: "required"
120+
}
121+
}
122+
];
123+
72124
ok( !v.valid(), "form is not valid after adding errors manually" );
73125
v.showErrors();
74126
equal( 0, container.find( ".error:not(input)" ).length, "There should be no error label in the container" );
@@ -110,7 +162,12 @@ test( "errorcontainer, show/hide only on submit", function() {
110162
ok( container.is( ":visible" ), "must be visible" );
111163

112164
$( "#firstname" ).val( "hix" ).keyup();
113-
$( "#testForm1" ).triggerHandler( "keyup", [jQuery.event.fix({ type: "keyup", target: $( "#firstname" )[0] })]);
165+
$( "#testForm1" ).triggerHandler( "keyup", [
166+
jQuery.event.fix({
167+
type: "keyup",
168+
target: $( "#firstname" )[ 0 ]
169+
})
170+
]);
114171
equal( 1, labelContainer.find( ".error:visible" ).length );
115172
equal( "There are 1 errors in your form.", container.html() );
116173

@@ -122,15 +179,15 @@ test( "test label used as error container", function(assert) {
122179
expect( 8 );
123180
var form = $( "#testForm16" ),
124181
field = $( "#testForm16text" );
125-
182+
126183
form.validate({
127184
errorPlacement: function( error, element ) {
128185
// Append error within linked label
129186
$( "label[for='" + element.attr( "id" ) + "']" ).append( error );
130187
},
131188
errorElement: "span"
132189
});
133-
190+
134191
ok( !field.valid() );
135192
equal( "Field Label", field.next( "label" ).contents( ":not(span)" ).text(), "container label isn't disrupted" );
136193
assert.hasError(field, "missing");
@@ -147,11 +204,11 @@ test( "test error placed adjacent to descriptive label", function(assert) {
147204
expect( 8 );
148205
var form = $( "#testForm16" ),
149206
field = $( "#testForm16text" );
150-
207+
151208
form.validate({
152209
errorElement: "span"
153210
});
154-
211+
155212
ok( !field.valid() );
156213
equal( 1, form.find( "label" ).length );
157214
equal( "Field Label", form.find( "label" ).text(), "container label isn't disrupted" );
@@ -168,11 +225,11 @@ test( "test descriptive label used alongside error label", function(assert) {
168225
expect( 8 );
169226
var form = $( "#testForm16" ),
170227
field = $( "#testForm16text" );
171-
228+
172229
form.validate({
173230
errorElement: "label"
174231
});
175-
232+
176233
ok( !field.valid() );
177234
equal( 1, form.find( "label.title" ).length );
178235
equal( "Field Label", form.find( "label.title" ).text(), "container label isn't disrupted" );
@@ -189,14 +246,14 @@ test( "test custom errorElement", function(assert) {
189246
expect( 4 );
190247
var form = $( "#userForm" ),
191248
field = $( "#username" );
192-
249+
193250
form.validate({
194251
messages: {
195252
username: "missing"
196253
},
197254
errorElement: "label"
198255
});
199-
256+
200257
ok( !field.valid() );
201258
assert.hasError( field, "missing", "Field should have error 'missing'" );
202259
field.val( "foo" );
@@ -208,9 +265,9 @@ test( "test existing label used as error element", function(assert) {
208265
expect( 4 );
209266
var form = $( "#testForm14" ),
210267
field = $( "#testForm14text" );
211-
212-
form.validate({errorElement: "label"});
213-
268+
269+
form.validate({ errorElement: "label" });
270+
214271
ok( !field.valid() );
215272
assert.hasError( field, "required" );
216273

@@ -223,9 +280,9 @@ test( "test existing non-label used as error element", function(assert) {
223280
expect( 4 );
224281
var form = $( "#testForm15" ),
225282
field = $( "#testForm15text" );
226-
227-
form.validate({errorElement: "span"});
228-
283+
284+
form.validate({ errorElement: "span" });
285+
229286
ok( !field.valid() );
230287
assert.hasError( field );
231288

test/messages.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test("predefined message not overwritten by addMethod(a, b, undefined)", functio
1111

1212
test("group error messages", function() {
1313
$.validator.addClassRules({
14-
requiredDateRange: {required:true, date:true, dateRange:true}
14+
requiredDateRange: { required: true, date: true, dateRange: true }
1515
});
1616
$.validator.addMethod("dateRange", function() {
1717
return new Date($("#fromDate").val()) < new Date($("#toDate").val());
@@ -57,7 +57,6 @@ test("read messages from metadata", function() {
5757
equal( form.find("#testGeneric9").next(".error:not(input)").text(), "email" );
5858
});
5959

60-
6160
test("read messages from metadata, with meta option specified, but no metadata in there", function() {
6261
var form = $("#testForm1clean");
6362
form.validate({

0 commit comments

Comments
 (0)