Skip to content

Commit 7ff3da1

Browse files
committed
Unit tests are linted and passing.
1 parent 6650146 commit 7ff3da1

17 files changed

+394
-283
lines changed

grunt.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ module.exports = function( grunt ) {
7979
"dist/jquery.min.js": [ "<banner>", "dist/jquery.js" ]
8080
},
8181
lint: {
82-
files: [ "grunt.js", "dist/jquery.js" ]
82+
files: [ "test/unit/**/*.js", "grunt.js", "dist/jquery.js" ]
8383
},
8484
qunit: {
8585
files: "test/index.html"
@@ -99,22 +99,50 @@ module.exports = function( grunt ) {
9999
trailing: true,
100100
undef: true,
101101
smarttabs: true,
102-
predef: [
103-
"define",
104-
"DOMParser",
105-
"__dirname"
106-
],
107102
maxerr: 100
108103
},
109104
globals: {
105+
define: true,
106+
DOMParser: true,
107+
__dirname: true,
110108
jQuery: true,
111109
global: true,
112110
module: true,
113111
exports: true,
114112
require: true,
115113
file: true,
116114
log: true,
117-
console: true
115+
console: true,
116+
QUnit: true,
117+
ok: true,
118+
equal: true,
119+
test: true,
120+
asyncTest: true,
121+
notEqual: true,
122+
deepEqual: true,
123+
strictEqual: true,
124+
notStrictEqual: true,
125+
start: true,
126+
stop: true,
127+
expect: true,
128+
raises: true,
129+
testIframe: true,
130+
testIframeWithCallback: true,
131+
createDashboardXML: true,
132+
moduleTeardown: true,
133+
testFoo: true,
134+
foobar: true,
135+
url: true,
136+
t: true,
137+
q: true,
138+
amdDefined: true,
139+
fireNative: true,
140+
hasPHP: true,
141+
isLocal: true,
142+
originaljQuery: true,
143+
"$": true,
144+
"original$": true
145+
118146
}
119147
},
120148
uglify: {}

test/unit/ajax.js

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ test(".ajax() - headers" , function() {
381381

382382
headers: requestHeaders,
383383
success: function( data , _ , xhr ) {
384-
var tmp = [];
384+
var tmp = [], i;
385385
for ( i in requestHeaders ) {
386386
tmp.push( i , ": " , requestHeaders[ i ] , "\n" );
387387
}
@@ -1000,7 +1000,7 @@ test("jQuery.param()", function() {
10001000

10011001
jQuery.ajaxSetup({ traditional: true });
10021002

1003-
var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
1003+
params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
10041004
equal( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
10051005

10061006
params = {someName: [1, 2, 3], regularThing: "blah" };
@@ -1038,10 +1038,13 @@ test("jQuery.param() Constructed prop values", function() {
10381038
this.prop = "val";
10391039
}
10401040

1041-
var params = { "test": new String("foo") };
1041+
var MyString = String,
1042+
MyNumber = Number,
1043+
params = { "test": new MyString("foo") };
1044+
10421045
equal( jQuery.param( params, false ), "test=foo", "Do not mistake new String() for a plain object" );
10431046

1044-
params = { "test": new Number(5) };
1047+
params = { "test": new MyNumber(5) };
10451048
equal( jQuery.param( params, false ), "test=5", "Do not mistake new Number() for a plain object" );
10461049

10471050
params = { "test": new Date() };
@@ -1054,14 +1057,20 @@ test("jQuery.param() Constructed prop values", function() {
10541057

10551058
test("synchronous request", function() {
10561059
expect(1);
1057-
ok( /^{ "data"/.test( jQuery.ajax({url: url("data/json_obj.js"), dataType: "text", async: false}).responseText ), "check returned text" );
1060+
var response = jQuery.ajax({
1061+
url: url("data/json_obj.js"),
1062+
dataType: "text",
1063+
async: false
1064+
}).responseText;
1065+
1066+
ok( /^\{ "data"/.test( response ), "check returned text" );
10581067
});
10591068

10601069
test("synchronous request with callbacks", function() {
10611070
expect(2);
10621071
var result;
10631072
jQuery.ajax({url: url("data/json_obj.js"), async: false, dataType: "text", success: function(data) { ok(true, "sucess callback executed"); result = data; } });
1064-
ok( /^{ "data"/.test( result ), "check returned text" );
1073+
ok( /^\{ "data"/.test( result ), "check returned text" );
10651074
});
10661075

10671076
test("pass-through request object", function() {
@@ -1113,8 +1122,9 @@ test("ajax cache", function () {
11131122
}
11141123
equal(i, 1, "Test to make sure only one 'no-cache' parameter is there");
11151124
ok(oldOne != "tobereplaced555", "Test to be sure parameter (if it was there) was replaced");
1116-
if(++count == 6)
1125+
if(++count == 6) {
11171126
start();
1127+
}
11181128
});
11191129

11201130
ok( jQuery.ajax({url: "data/text.php", cache:false}), "test with no parameters" );
@@ -1372,7 +1382,11 @@ jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label )
13721382
expect(24);
13731383

13741384
var count = 0;
1375-
function plus(){ if ( ++count == 20 ) start(); }
1385+
function plus(){
1386+
if ( ++count == 20 ) {
1387+
start();
1388+
}
1389+
}
13761390

13771391
stop();
13781392

@@ -1858,19 +1872,19 @@ test("jQuery.getJSON(String, Function) - JSON object", function() {
18581872
});
18591873
});
18601874

1861-
test("jQuery.getJSON - Using Native JSON", function() {
1875+
asyncTest("jQuery.getJSON - Using Native JSON", function() {
18621876
expect(2);
18631877

18641878
var old = window.JSON;
1865-
JSON = {
1866-
parse: function(str){
1879+
1880+
window.JSON = {
1881+
parse: function(str) {
18671882
ok( true, "Verifying that parse method was run" );
18681883
return true;
18691884
}
18701885
};
18711886

1872-
stop();
1873-
jQuery.getJSON(url("data/json.php"), function(json) {
1887+
jQuery.getJSON(url("data/json.php"), function( json ) {
18741888
window.JSON = old;
18751889
equal( json, true, "Verifying return value" );
18761890
start();
@@ -1930,15 +1944,19 @@ test("jQuery.post(String, Hash, Function) - simple with xml", function() {
19301944
equal( jQuery("calculation", this).text(), "5-2", "Check for XML" );
19311945
equal( jQuery("result", this).text(), "3", "Check for XML" );
19321946
});
1933-
if ( ++done === 2 ) start();
1947+
if ( ++done === 2 ) {
1948+
start();
1949+
}
19341950
});
19351951

19361952
jQuery.post(url("data/name.php?xml=5-2"), {}, function(xml){
19371953
jQuery("math", xml).each(function() {
19381954
equal( jQuery("calculation", this).text(), "5-2", "Check for XML" );
19391955
equal( jQuery("result", this).text(), "3", "Check for XML" );
19401956
});
1941-
if ( ++done === 2 ) start();
1957+
if ( ++done === 2 ) {
1958+
start();
1959+
}
19421960
});
19431961
});
19441962

@@ -2196,14 +2214,22 @@ test("jQuery ajax - failing cross-domain", function() {
21962214
url: "http://somewebsitethatdoesnotexist-67864863574657654.com",
21972215
success: function(){ ok( false , "success" ); },
21982216
error: function(xhr,_,e){ ok( true , "file not found: " + xhr.status + " => " + e ); },
2199-
complete: function() { if ( ! --i ) start(); }
2217+
complete: function() {
2218+
if ( ! --i ) {
2219+
start();
2220+
}
2221+
}
22002222
});
22012223

22022224
jQuery.ajax({
22032225
url: "http://www.google.com",
22042226
success: function(){ ok( false , "success" ); },
22052227
error: function(xhr,_,e){ ok( true , "access denied: " + xhr.status + " => " + e ); },
2206-
complete: function() { if ( ! --i ) start(); }
2228+
complete: function() {
2229+
if ( ! --i ) {
2230+
start();
2231+
}
2232+
}
22072233
});
22082234

22092235
});
@@ -2498,7 +2524,7 @@ test( "jQuery.domManip - script in comments are properly evaluated (#11402)", fu
24982524
});
24992525

25002526
test("jQuery.ajax - active counter", function() {
2501-
ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active );
2527+
ok( jQuery.active === 0, "ajax active counter should be zero: " + jQuery.active );
25022528
});
25032529

25042530
}

test/unit/attributes.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ test("attr(Hash)", function() {
156156
expect(3);
157157
var pass = true;
158158
jQuery("div").attr({foo: "baz", zoo: "ping"}).each(function(){
159-
if ( this.getAttribute("foo") != "baz" && this.getAttribute("zoo") != "ping" ) pass = false;
159+
if ( this.getAttribute("foo") != "baz" && this.getAttribute("zoo") != "ping" ) {
160+
pass = false;
161+
}
160162
});
161163
ok( pass, "Set Multiple Attributes" );
162164
equal( jQuery("#text1").attr({value: function() { return this.id; }})[0].value, "text1", "Set attribute to computed value #1" );
@@ -354,9 +356,12 @@ test("attr(String, Object)", function() {
354356
equal( $radio.val(), "sup", "Value is not reset when type is set after value on a radio" );
355357

356358
// Setting attributes on svg elements (bug #3116)
357-
var $svg = jQuery("<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' baseProfile='full' width='200' height='200'>"
358-
+ "<circle cx='200' cy='200' r='150' />"
359-
+ "</svg>").appendTo("body");
359+
var $svg = jQuery(
360+
"<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' baseProfile='full' width='200' height='200'>" +
361+
362+
"<circle cx='200' cy='200' r='150' />" +
363+
"</svg>"
364+
).appendTo("body");
360365
equal( $svg.attr("cx", 100).attr("cx"), "100", "Set attribute on svg element" );
361366
$svg.remove();
362367

@@ -811,7 +816,7 @@ var testVal = function(valueObj) {
811816
j.val(valueObj( "asdf" ));
812817
equal( j.val(), "asdf", "Check node,textnode,comment with val()" );
813818
j.removeAttr("value");
814-
}
819+
};
815820

816821
test("val(String/Number)", function() {
817822
testVal(bareObj);
@@ -889,7 +894,7 @@ test("val(Function) with incoming value", function() {
889894
test("val(select) after form.reset() (Bug #2551)", function() {
890895
expect(3);
891896

892-
jQuery("<form id='kk' name='kk'><select id='kkk'><option value='cf'>cf</option><option value='gf'>gf</option></select></form>").appendTo("#qunit-fixture");
897+
jQuery("<form id='kk' name='kk'><select id='kkk'><option value='cf'>cf</option><option value='gf'>gf</option></select></form>").appendTo("#qunit-fixture");
893898

894899
jQuery("#kkk").val( "gf" );
895900

@@ -972,7 +977,9 @@ test("addClass(Function) with incoming value", function() {
972977

973978
var pass = true;
974979
for ( var i = 0; i < div.length; i++ ) {
975-
if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
980+
if ( div.get(i).className.indexOf("test") == -1 ) {
981+
pass = false;
982+
}
976983
}
977984
ok( pass, "Add Class" );
978985
});
@@ -1180,7 +1187,8 @@ test("addClass, removeClass, hasClass", function() {
11801187
ok( jq.hasClass("hi"), "Check has1" );
11811188
ok( jq.hasClass("bar"), "Check has2" );
11821189

1183-
var jq = jQuery("<p class='class1\nclass2\tcla.ss3\n\rclass4'></p>");
1190+
jq = jQuery("<p class='class1\nclass2\tcla.ss3\n\rclass4'></p>");
1191+
11841192
ok( jq.hasClass("class1"), "Check hasClass with line feed" );
11851193
ok( jq.is(".class1"), "Check is with line feed" );
11861194
ok( jq.hasClass("class2"), "Check hasClass with tab" );
@@ -1190,13 +1198,13 @@ test("addClass, removeClass, hasClass", function() {
11901198
ok( jq.is(".class4"), "Check is with carriage return" );
11911199

11921200
jq.removeClass("class2");
1193-
ok( jq.hasClass("class2")==false, "Check the class has been properly removed" );
1201+
ok( jq.hasClass("class2")===false, "Check the class has been properly removed" );
11941202
jq.removeClass("cla");
11951203
ok( jq.hasClass("cla.ss3"), "Check the dotted class has not been removed" );
11961204
jq.removeClass("cla.ss3");
1197-
ok( jq.hasClass("cla.ss3")==false, "Check the dotted class has been removed" );
1205+
ok( jq.hasClass("cla.ss3")===false, "Check the dotted class has been removed" );
11981206
jq.removeClass("class4");
1199-
ok( jq.hasClass("class4")==false, "Check the class has been properly removed" );
1207+
ok( jq.hasClass("class4")===false, "Check the class has been properly removed" );
12001208
});
12011209

12021210
test("contents().hasClass() returns correct values", function() {

test/unit/callbacks.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ var output,
1212
outputB = addToOutput( "B" ),
1313
outputC = addToOutput( "C" ),
1414
tests = {
15-
"": "XABC X XABCABCC X XBB X XABA X",
16-
"once": "XABC X X X X X XABA X",
17-
"memory": "XABC XABC XABCABCCC XA XBB XB XABA XC",
18-
"unique": "XABC X XABCA X XBB X XAB X",
19-
"stopOnFalse": "XABC X XABCABCC X XBB X XA X",
20-
"once memory": "XABC XABC X XA X XA XABA XC",
21-
"once unique": "XABC X X X X X XAB X",
22-
"once stopOnFalse": "XABC X X X X X XA X",
23-
"memory unique": "XABC XA XABCA XA XBB XB XAB XC",
24-
"memory stopOnFalse": "XABC XABC XABCABCCC XA XBB XB XA X",
25-
"unique stopOnFalse": "XABC X XABCA X XBB X XA X"
15+
"": "XABC X XABCABCC X XBB X XABA X",
16+
"once": "XABC X X X X X XABA X",
17+
"memory": "XABC XABC XABCABCCC XA XBB XB XABA XC",
18+
"unique": "XABC X XABCA X XBB X XAB X",
19+
"stopOnFalse": "XABC X XABCABCC X XBB X XA X",
20+
"once memory": "XABC XABC X XA X XA XABA XC",
21+
"once unique": "XABC X X X X X XAB X",
22+
"once stopOnFalse": "XABC X X X X X XA X",
23+
"memory unique": "XABC XA XABCA XA XBB XB XAB XC",
24+
"memory stopOnFalse": "XABC XABC XABCABCCC XA XBB XB XA X",
25+
"unique stopOnFalse": "XABC X XABCA X XBB X XA X"
2626
},
2727
filters = {
2828
"no filter": undefined,

0 commit comments

Comments
 (0)