Skip to content

Commit

Permalink
Unit tests are linted and passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Jun 21, 2012
1 parent 6650146 commit 7ff3da1
Show file tree
Hide file tree
Showing 17 changed files with 394 additions and 283 deletions.
42 changes: 35 additions & 7 deletions grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module.exports = function( grunt ) {
"dist/jquery.min.js": [ "<banner>", "dist/jquery.js" ]
},
lint: {
files: [ "grunt.js", "dist/jquery.js" ]
files: [ "test/unit/**/*.js", "grunt.js", "dist/jquery.js" ]
},
qunit: {
files: "test/index.html"
Expand All @@ -99,22 +99,50 @@ module.exports = function( grunt ) {
trailing: true,
undef: true,
smarttabs: true,
predef: [
"define",
"DOMParser",
"__dirname"
],
maxerr: 100
},
globals: {
define: true,
DOMParser: true,
__dirname: true,
jQuery: true,
global: true,
module: true,
exports: true,
require: true,
file: true,
log: true,
console: true
console: true,
QUnit: true,

This comment has been minimized.

Copy link
@scottgonzalez

scottgonzalez Jun 25, 2012

Member

You should really split this into multiple lint tasks so that you can keep the test-only globals separate.

This comment has been minimized.

Copy link
@rwaldron

rwaldron Jun 25, 2012

Author Member

Agreed - this was definitely just an initial pass to get through mess... I'll work on that tomorrow.

ok: true,
equal: true,
test: true,
asyncTest: true,
notEqual: true,
deepEqual: true,
strictEqual: true,
notStrictEqual: true,
start: true,
stop: true,
expect: true,
raises: true,
testIframe: true,
testIframeWithCallback: true,
createDashboardXML: true,
moduleTeardown: true,
testFoo: true,
foobar: true,
url: true,
t: true,
q: true,
amdDefined: true,
fireNative: true,
hasPHP: true,
isLocal: true,
originaljQuery: true,
"$": true,
"original$": true

}
},
uglify: {}
Expand Down
62 changes: 44 additions & 18 deletions test/unit/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ test(".ajax() - headers" , function() {

headers: requestHeaders,
success: function( data , _ , xhr ) {
var tmp = [];
var tmp = [], i;
for ( i in requestHeaders ) {
tmp.push( i , ": " , requestHeaders[ i ] , "\n" );
}
Expand Down Expand Up @@ -1000,7 +1000,7 @@ test("jQuery.param()", function() {

jQuery.ajaxSetup({ traditional: true });

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

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

var params = { "test": new String("foo") };
var MyString = String,
MyNumber = Number,

This comment has been minimized.

Copy link
@Krinkle

Krinkle Jun 22, 2012

Member

Maybe jshint should get an option to whitelist this, so we could use comment-option within this function.

Either way, this is a pretty nice hack to get around that :wink2:

This comment has been minimized.

Copy link
@mikesherov

mikesherov Jun 22, 2012

Member

@Krinkle, pull request it!

params = { "test": new MyString("foo") };

equal( jQuery.param( params, false ), "test=foo", "Do not mistake new String() for a plain object" );

params = { "test": new Number(5) };
params = { "test": new MyNumber(5) };

This comment has been minimized.

Copy link
@martin-g

martin-g Jul 2, 2012

Is it wrong to just use: {"test": Number(5) } ?
This is how I solved this jshint issue locally but maybe it is not correct ?!

This comment has been minimized.

Copy link
@Krinkle

Krinkle Jul 2, 2012

Member

See 10 lines up. This is a work-around to avoid triggering JSHint.

JSHint could get smarter and invalidate this too, which would be fair. jQuery is not using Number as a constructor, we're just testing for it here. So we basically need an option in jshint so we can tolerat it in this function with a local /*jshint */ rule set.

This comment has been minimized.

Copy link
@rwaldron

rwaldron Jul 2, 2012

Author Member

I honestly think there are better uses of our time then worrying about this

equal( jQuery.param( params, false ), "test=5", "Do not mistake new Number() for a plain object" );

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

test("synchronous request", function() {
expect(1);
ok( /^{ "data"/.test( jQuery.ajax({url: url("data/json_obj.js"), dataType: "text", async: false}).responseText ), "check returned text" );
var response = jQuery.ajax({
url: url("data/json_obj.js"),
dataType: "text",
async: false
}).responseText;

ok( /^\{ "data"/.test( response ), "check returned text" );
});

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

test("pass-through request object", function() {
Expand Down Expand Up @@ -1113,8 +1122,9 @@ test("ajax cache", function () {
}
equal(i, 1, "Test to make sure only one 'no-cache' parameter is there");
ok(oldOne != "tobereplaced555", "Test to be sure parameter (if it was there) was replaced");
if(++count == 6)
if(++count == 6) {
start();
}
});

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

var count = 0;
function plus(){ if ( ++count == 20 ) start(); }
function plus(){
if ( ++count == 20 ) {
start();
}
}

stop();

Expand Down Expand Up @@ -1858,19 +1872,19 @@ test("jQuery.getJSON(String, Function) - JSON object", function() {
});
});

test("jQuery.getJSON - Using Native JSON", function() {
asyncTest("jQuery.getJSON - Using Native JSON", function() {
expect(2);

var old = window.JSON;
JSON = {
parse: function(str){

window.JSON = {
parse: function(str) {
ok( true, "Verifying that parse method was run" );
return true;
}
};

stop();
jQuery.getJSON(url("data/json.php"), function(json) {
jQuery.getJSON(url("data/json.php"), function( json ) {
window.JSON = old;
equal( json, true, "Verifying return value" );
start();
Expand Down Expand Up @@ -1930,15 +1944,19 @@ test("jQuery.post(String, Hash, Function) - simple with xml", function() {
equal( jQuery("calculation", this).text(), "5-2", "Check for XML" );
equal( jQuery("result", this).text(), "3", "Check for XML" );
});
if ( ++done === 2 ) start();
if ( ++done === 2 ) {
start();
}
});

jQuery.post(url("data/name.php?xml=5-2"), {}, function(xml){
jQuery("math", xml).each(function() {
equal( jQuery("calculation", this).text(), "5-2", "Check for XML" );
equal( jQuery("result", this).text(), "3", "Check for XML" );
});
if ( ++done === 2 ) start();
if ( ++done === 2 ) {
start();
}
});
});

Expand Down Expand Up @@ -2196,14 +2214,22 @@ test("jQuery ajax - failing cross-domain", function() {
url: "http://somewebsitethatdoesnotexist-67864863574657654.com",
success: function(){ ok( false , "success" ); },
error: function(xhr,_,e){ ok( true , "file not found: " + xhr.status + " => " + e ); },
complete: function() { if ( ! --i ) start(); }
complete: function() {
if ( ! --i ) {
start();
}
}
});

jQuery.ajax({
url: "http://www.google.com",
success: function(){ ok( false , "success" ); },
error: function(xhr,_,e){ ok( true , "access denied: " + xhr.status + " => " + e ); },
complete: function() { if ( ! --i ) start(); }
complete: function() {
if ( ! --i ) {
start();
}
}
});

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

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

}
30 changes: 19 additions & 11 deletions test/unit/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ test("attr(Hash)", function() {
expect(3);
var pass = true;
jQuery("div").attr({foo: "baz", zoo: "ping"}).each(function(){
if ( this.getAttribute("foo") != "baz" && this.getAttribute("zoo") != "ping" ) pass = false;
if ( this.getAttribute("foo") != "baz" && this.getAttribute("zoo") != "ping" ) {
pass = false;
}
});
ok( pass, "Set Multiple Attributes" );
equal( jQuery("#text1").attr({value: function() { return this.id; }})[0].value, "text1", "Set attribute to computed value #1" );
Expand Down Expand Up @@ -354,9 +356,12 @@ test("attr(String, Object)", function() {
equal( $radio.val(), "sup", "Value is not reset when type is set after value on a radio" );

// Setting attributes on svg elements (bug #3116)
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'>"
+ "<circle cx='200' cy='200' r='150' />"
+ "</svg>").appendTo("body");
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'>" +

"<circle cx='200' cy='200' r='150' />" +
"</svg>"
).appendTo("body");
equal( $svg.attr("cx", 100).attr("cx"), "100", "Set attribute on svg element" );
$svg.remove();

Expand Down Expand Up @@ -811,7 +816,7 @@ var testVal = function(valueObj) {
j.val(valueObj( "asdf" ));
equal( j.val(), "asdf", "Check node,textnode,comment with val()" );
j.removeAttr("value");
}
};

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

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

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

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

var pass = true;
for ( var i = 0; i < div.length; i++ ) {
if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
if ( div.get(i).className.indexOf("test") == -1 ) {
pass = false;
}
}
ok( pass, "Add Class" );
});
Expand Down Expand Up @@ -1180,7 +1187,8 @@ test("addClass, removeClass, hasClass", function() {
ok( jq.hasClass("hi"), "Check has1" );
ok( jq.hasClass("bar"), "Check has2" );

var jq = jQuery("<p class='class1\nclass2\tcla.ss3\n\rclass4'></p>");
jq = jQuery("<p class='class1\nclass2\tcla.ss3\n\rclass4'></p>");

ok( jq.hasClass("class1"), "Check hasClass with line feed" );
ok( jq.is(".class1"), "Check is with line feed" );
ok( jq.hasClass("class2"), "Check hasClass with tab" );
Expand All @@ -1190,13 +1198,13 @@ test("addClass, removeClass, hasClass", function() {
ok( jq.is(".class4"), "Check is with carriage return" );

jq.removeClass("class2");
ok( jq.hasClass("class2")==false, "Check the class has been properly removed" );
ok( jq.hasClass("class2")===false, "Check the class has been properly removed" );
jq.removeClass("cla");
ok( jq.hasClass("cla.ss3"), "Check the dotted class has not been removed" );
jq.removeClass("cla.ss3");
ok( jq.hasClass("cla.ss3")==false, "Check the dotted class has been removed" );
ok( jq.hasClass("cla.ss3")===false, "Check the dotted class has been removed" );
jq.removeClass("class4");
ok( jq.hasClass("class4")==false, "Check the class has been properly removed" );
ok( jq.hasClass("class4")===false, "Check the class has been properly removed" );
});

test("contents().hasClass() returns correct values", function() {
Expand Down
22 changes: 11 additions & 11 deletions test/unit/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ var output,
outputB = addToOutput( "B" ),
outputC = addToOutput( "C" ),
tests = {
"": "XABC X XABCABCC X XBB X XABA X",
"once": "XABC X X X X X XABA X",
"memory": "XABC XABC XABCABCCC XA XBB XB XABA XC",
"unique": "XABC X XABCA X XBB X XAB X",
"stopOnFalse": "XABC X XABCABCC X XBB X XA X",
"once memory": "XABC XABC X XA X XA XABA XC",
"once unique": "XABC X X X X X XAB X",
"once stopOnFalse": "XABC X X X X X XA X",
"memory unique": "XABC XA XABCA XA XBB XB XAB XC",
"memory stopOnFalse": "XABC XABC XABCABCCC XA XBB XB XA X",
"unique stopOnFalse": "XABC X XABCA X XBB X XA X"
"": "XABC X XABCABCC X XBB X XABA X",
"once": "XABC X X X X X XABA X",
"memory": "XABC XABC XABCABCCC XA XBB XB XABA XC",
"unique": "XABC X XABCA X XBB X XAB X",
"stopOnFalse": "XABC X XABCABCC X XBB X XA X",
"once memory": "XABC XABC X XA X XA XABA XC",
"once unique": "XABC X X X X X XAB X",
"once stopOnFalse": "XABC X X X X X XA X",
"memory unique": "XABC XA XABCA XA XBB XB XAB XC",
"memory stopOnFalse": "XABC XABC XABCABCCC XA XBB XB XA X",
"unique stopOnFalse": "XABC X XABCA X XBB X XA X"
},
filters = {
"no filter": undefined,
Expand Down
Loading

4 comments on commit 7ff3da1

@mikesherov
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BRAVO.

@Krinkle
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@rwaldron
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks guys :)

@timmywil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘

Please sign in to comment.