Commit 7ff3da18 authored by Rick Waldron's avatar Rick Waldron

Unit tests are linted and passing.

parent 66501469
......@@ -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"
......@@ -99,14 +99,12 @@ 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,
......@@ -114,7 +112,37 @@ module.exports = function( grunt ) {
require: true,
file: true,
log: true,
console: true
console: true,
QUnit: true,
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: {}
......
......@@ -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" );
}
......@@ -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" };
......@@ -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,
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) };
equal( jQuery.param( params, false ), "test=5", "Do not mistake new Number() for a plain object" );
params = { "test": new Date() };
......@@ -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() {
......@@ -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" );
......@@ -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();
......@@ -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();
......@@ -1930,7 +1944,9 @@ 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){
......@@ -1938,7 +1954,9 @@ 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();
}
});
});
......@@ -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();
}
}
});
});
......@@ -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 );
});
}
......@@ -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" );
......@@ -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();
......@@ -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);
......@@ -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" );
......@@ -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" );
});
......@@ -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" );
......@@ -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() {
......
......@@ -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,
......
......@@ -322,10 +322,10 @@ test("type", function() {
equal( jQuery.type(document.getElementsByTagName("*")), "object", "NodeList" );
});
test("isPlainObject", function() {
asyncTest("isPlainObject", function() {
expect(15);
stop();
var iframe;
// The use case that we want to match
ok(jQuery.isPlainObject({}), "{}");
......@@ -341,7 +341,7 @@ test("isPlainObject", function() {
ok(!jQuery.isPlainObject([]), "array");
// Instantiated objects shouldn't be matched
ok(!jQuery.isPlainObject(new Date), "new Date");
ok(!jQuery.isPlainObject(new Date()), "new Date");
var fn = function(){};
......@@ -349,14 +349,14 @@ test("isPlainObject", function() {
ok(!jQuery.isPlainObject(fn), "fn");
// Again, instantiated objects shouldn't be matched
ok(!jQuery.isPlainObject(new fn), "new fn (no methods)");
ok(!jQuery.isPlainObject(new fn()), "new fn (no methods)");
// Makes the function a little more realistic
// (and harder to detect, incidentally)
fn.prototype = {someMethod: function(){}};
// Again, instantiated objects shouldn't be matched
ok(!jQuery.isPlainObject(new fn), "new fn");
ok(!jQuery.isPlainObject(new fn()), "new fn");
// DOM Element
ok(!jQuery.isPlainObject(document.createElement("div")), "DOM Element");
......@@ -372,12 +372,12 @@ test("isPlainObject", function() {
}
try {
var iframe = document.createElement("iframe");
iframe = document.createElement("iframe");
document.body.appendChild(iframe);
window.iframeDone = function(otherObject){
// Objects from other windows should be matched
ok(jQuery.isPlainObject(new otherObject), "new otherObject");
ok(jQuery.isPlainObject(new otherObject()), "new otherObject");
document.body.removeChild( iframe );
start();
};
......@@ -474,7 +474,7 @@ test("isFunction", function() {
ok( jQuery.isFunction(fn), "Recursive Function Call" );
fn({ some: "data" });
};
}
callme(function(){
callme(function(){});
......@@ -482,7 +482,7 @@ test("isFunction", function() {
});
test( "isNumeric", function() {
expect( 37 );
expect( 36 );
var t = jQuery.isNumeric,
Traditionalists = function(n) {
......@@ -501,7 +501,9 @@ test( "isNumeric", function() {
ok( t(0), "Zero integer number");
ok( t(32), "Positive integer number");
ok( t("040"), "Octal integer literal string");
ok( t(0144), "Octal integer literal");
// OctalIntegerLiteral has been deprecated since ES3/1999
// It doesn't pass lint, so disabling until a solution can be found
//ok( t(0144), "Octal integer literal");
ok( t("0xFF"), "Hexadecimal integer literal string");
ok( t(0xFFF), "Hexadecimal integer literal");
ok( t("-1.6"), "Negative floating point string");
......@@ -529,7 +531,7 @@ test( "isNumeric", function() {
equal( t(rong), false, "Custom .toString returning non-number");
equal( t({}), false, "Empty object");
equal( t(function(){} ), false, "Instance of a function");
equal( t( new Date ), false, "Instance of a Date");
equal( t( new Date() ), false, "Instance of a Date");
equal( t(function(){} ), false, "Instance of a function");
});
......@@ -705,8 +707,8 @@ test("toArray()", function() {
expect(1);
deepEqual( jQuery("#qunit-fixture p").toArray(),
q("firstp","ap","sndp","en","sap","first"),
"Convert jQuery object to an Array" )
})
"Convert jQuery object to an Array" );
});
test("inArray()", function() {
expect(19);
......@@ -754,7 +756,7 @@ test("get(-Number)",function() {
expect(2);
equal( jQuery("p").get(-1), document.getElementById("first"), "Get a single element with negative index" );
strictEqual( jQuery("#firstp").get(-2), undefined, "Try get with index negative index larger then elements count" );
})
});
test("each(Function)", function() {
expect(1);
......@@ -762,7 +764,9 @@ test("each(Function)", function() {
div.each(function(){this.foo = "zoo";});
var pass = true;
for ( var i = 0; i < div.size(); i++ ) {
if ( div.get(i).foo != "zoo" ) pass = false;
if ( div.get(i).foo != "zoo" ) {
pass = false;
}
}
ok( pass, "Execute a function, Relative" );
});
......@@ -813,36 +817,37 @@ test("map()", function() {
"Single Map"
);
var keys, values, scripts, nonsense, mapped, flat;
//for #2616
var keys = jQuery.map( {a:1,b:2}, function( v, k ){
keys = jQuery.map( {a:1,b:2}, function( v, k ){
return k;
});
equal( keys.join(""), "ab", "Map the keys from a hash to an array" );
var values = jQuery.map( {a:1,b:2}, function( v, k ){
values = jQuery.map( {a:1,b:2}, function( v, k ){
return v;
});
equal( values.join(""), "12", "Map the values from a hash to an array" );
// object with length prop
var values = jQuery.map( {a:1,b:2, length:3}, function( v, k ){
values = jQuery.map( {a:1,b:2, length:3}, function( v, k ){
return v;
});
equal( values.join(""), "123", "Map the values from a hash with a length property to an array" );
var scripts = document.getElementsByTagName("script");
var mapped = jQuery.map( scripts, function( v, k ){
scripts = document.getElementsByTagName("script");
mapped = jQuery.map( scripts, function( v, k ){
return v;
});
equal( mapped.length, scripts.length, "Map an array(-like) to a hash" );
var nonsense = document.getElementsByTagName("asdf");
var mapped = jQuery.map( nonsense, function( v, k ){
nonsense = document.getElementsByTagName("asdf");
mapped = jQuery.map( nonsense, function( v, k ){
return v;
});
equal( mapped.length, nonsense.length, "Map an empty array(-like) to a hash" );
var flat = jQuery.map( Array(4), function( v, k ){
flat = jQuery.map( Array(4), function( v, k ){
return k % 2 ? k : [k,k,k];//try mixing array and regular returns
});
equal( flat.join(""), "00012223", "try the new flatten technique(#2616)" );
......@@ -909,7 +914,7 @@ test("jQuery.extend(Object, Object)", function() {
deepEqual( empty.foo, optionsWithLength.foo, "The length property must copy correctly" );
empty = {};
var optionsWithDate = { foo: { date: new Date } };
var optionsWithDate = { foo: { date: new Date() } };
jQuery.extend(true, empty, optionsWithDate);
deepEqual( empty.foo, optionsWithDate.foo, "Dates copy correctly" );
......@@ -926,7 +931,8 @@ test("jQuery.extend(Object, Object)", function() {
jQuery.extend(true, empty, optionsWithCustomObject);
ok( empty.foo && empty.foo.date === customObject, "Custom objects copy correctly" );
var ret = jQuery.extend(true, { foo: 4 }, { foo: new Number(5) } );
var MyNumber = Number;
var ret = jQuery.extend(true, { foo: 4 }, { foo: new MyNumber(5) } );
ok( ret.foo == 5, "Wrapped numbers copy correctly" );
var nullUndef;
......@@ -944,13 +950,13 @@ test("jQuery.extend(Object, Object)", function() {
jQuery.extend(true, target, recursive);
deepEqual( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
var ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
equal( ret.foo.length, 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" );
var ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
var ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
ok( typeof ret.foo !== "undefined", "Make sure a null value doesn't crash with deep extend, for #1908" );
var obj = { foo:null };
......@@ -969,7 +975,7 @@ test("jQuery.extend(Object, Object)", function() {
options2Copy = { xstring2: "xx", xxx: "newstringx" },
merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
var settings = jQuery.extend({}, defaults, options1, options2);
settings = jQuery.extend({}, defaults, options1, options2);
deepEqual( settings, merged2, "Check if extended: settings must be extended" );
deepEqual( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
deepEqual( options1, options1Copy, "Check if not modified: options1 must not be modified" );
......@@ -994,7 +1000,12 @@ test("jQuery.each(Object,Function)", function() {
jQuery.each([1,2,3], function(i,v){ total += v; });
equal( total, 6, "Looping over an array" );
total = 0;
jQuery.each([1,2,3], function(i,v){ total += v; if ( i == 1 ) return false; });
jQuery.each([1,2,3], function(i,v){
total += v;
if ( i == 1 ) {
return false;
}
});
equal( total, 3, "Looping over an array, with break" );
total = 0;
jQuery.each({"a":1,"b":2,"c":3}, function(i,v){ total += v; });
......
......@@ -73,21 +73,21 @@ test("css(String|Hash)", function() {
div = jQuery("#nothiddendiv");
var child = jQuery("#nothiddendivchild");
equal( parseInt(div.css("fontSize")), 16, "Verify fontSize px set." );
equal( parseInt(div.css("font-size")), 16, "Verify fontSize px set." );
equal( parseInt(child.css("fontSize")), 16, "Verify fontSize px set." );
equal( parseInt(child.css("font-size")), 16, "Verify fontSize px set." );
equal( parseInt(div.css("fontSize"), 10), 16, "Verify fontSize px set." );
equal( parseInt(div.css("font-size"), 10), 16, "Verify fontSize px set." );
equal( parseInt(child.css("fontSize"), 10), 16, "Verify fontSize px set." );
equal( parseInt(child.css("font-size"), 10), 16, "Verify fontSize px set." );
child.css("height", "100%");
equal( child[0].style.height, "100%", "Make sure the height is being set correctly." );
child.attr("class", "em");
equal( parseInt(child.css("fontSize")), 32, "Verify fontSize em set." );
equal( parseInt(child.css("fontSize"), 10), 32, "Verify fontSize em set." );
// Have to verify this as the result depends upon the browser's CSS
// support for font-size percentages
child.attr("class", "prct");
var prctval = parseInt(child.css("fontSize")), checkval = 0;
var prctval = parseInt(child.css("fontSize"), 10), checkval = 0;
if ( prctval === 16 || prctval === 24 ) {
checkval = prctval;
}
......@@ -314,8 +314,8 @@ test("css(String, Function)", function() {
index = 0;
jQuery("#cssFunctionTest div").each(function() {
var computedSize = jQuery(this).css("font-size")
var expectedSize = sizes[index]
var computedSize = jQuery(this).css("font-size");
var expectedSize = sizes[index];
equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++;
});
......@@ -344,7 +344,7 @@ test("css(String, Function) with incoming value", function() {
index = 0;
jQuery("#cssFunctionTest div").css("font-size", function(i, computedSize) {
var expectedSize = sizes[index]
var expectedSize = sizes[index];
equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++;
return computedSize;
......@@ -374,8 +374,8 @@ test("css(Object) where values are Functions", function() {
index = 0;
jQuery("#cssFunctionTest div").each(function() {
var computedSize = jQuery(this).css("font-size")
var expectedSize = sizes[index]
var computedSize = jQuery(this).css("font-size");
var expectedSize = sizes[index];
equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++;
});
......@@ -404,7 +404,7 @@ test("css(Object) where values are Functions with incoming values", function() {
index = 0;
jQuery("#cssFunctionTest div").css({"font-size": function(i, computedSize) {
var expectedSize = sizes[index]
var expectedSize = sizes[index];
equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++;
return computedSize;
......@@ -444,7 +444,9 @@ test("show(); hide()", function() {
var pass = true;
div = jQuery("#qunit-fixture div");
div.show().each(function(){
if ( this.style.display == "none" ) pass = false;
if ( this.style.display == "none" ) {
pass = false;
}
});
ok( pass, "Show" );
......@@ -700,7 +702,7 @@ test("can't get background-position in IE<9, see #10796", function() {
"12em center",
"+12em center",
"12.2em center",
"center center",
"center center"
],
l = units.length,
i = 0;
......
......@@ -18,10 +18,12 @@ function dataTests (elem) {
return cacheLength;
}
var oldCacheLength, dataObj, internalDataObj, expected, actual;
equal( jQuery.data(elem, "foo"), undefined, "No data exists initially" );
strictEqual( jQuery.hasData(elem), false, "jQuery.hasData agrees no data exists initially" );
var dataObj = jQuery.data(elem);
dataObj = jQuery.data(elem);
equal( typeof dataObj, "object", "Calling data with no args gives us a data object reference" );
strictEqual( jQuery.data(elem), dataObj, "Calling jQuery.data returns the same data object when called multiple times" );
......@@ -52,7 +54,7 @@ function dataTests (elem) {
equal( jQuery._data(elem, "foo"), "foo2", "Setting internal data works" );
equal( jQuery.data(elem, "foo"), "foo1", "Setting internal data does not override user data" );
var internalDataObj = jQuery._data( elem );
internalDataObj = jQuery._data( elem );
ok( internalDataObj, "Internal data object exists" );
notStrictEqual( dataObj, internalDataObj, "Internal data object is not the same as user data object" );
......@@ -80,14 +82,14 @@ function dataTests (elem) {
jQuery.removeData( elem, "foo", true );
if (elem.nodeType) {
var oldCacheLength = getCacheLength();
oldCacheLength = getCacheLength();
jQuery.removeData(elem, "foo");
equal( getCacheLength(), oldCacheLength - 1, "Removing the last item in the data object destroys it" );
}
else {
jQuery.removeData(elem, "foo");
var expected, actual;
if (jQuery.support.deleteExpando) {
expected = false;
......@@ -117,7 +119,7 @@ function dataTests (elem) {
jQuery.removeData(elem, "foo");
equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) jQuery.removeData for user data does not remove internal data" );
if (elem.nodeType) {
if ( elem.nodeType ) {
oldCacheLength = getCacheLength();
jQuery.removeData(elem, "foo", true);
equal( getCacheLength(), oldCacheLength - 1, "Removing the last item in the internal data object also destroys the user data object when it is empty" );
......@@ -204,9 +206,9 @@ test(".data(String) and .data(String, Object)", function() {
div = parent.children();
parent
.bind("getData", function(){ ok( false, "getData bubbled." ) })
.bind("setData", function(){ ok( false, "setData bubbled." ) })
.bind("changeData", function(){ ok( false, "changeData bubbled." ) });
.bind("getData", function(){ ok( false, "getData bubbled." ); })
.bind("setData", function(){ ok( false, "setData bubbled." ); })
.bind("changeData", function(){ ok( false, "changeData bubbled." ); });
ok( div.data("test") === undefined, "Check for no data exists" );
......@@ -319,7 +321,12 @@ test("data-* attributes", function() {
child.data("ignored", "cache");
equal( child.data("ignored"), "cache", "Cached data used before DOM data-* fallback");
var obj = child.data(), obj2 = dummy.data(), check = [ "myobj", "ignored", "other" ], num = 0, num2 = 0;
var prop,
obj = child.data(),
obj2 = dummy.data(),
check = [ "myobj", "ignored", "other" ],
num = 0,
num2 = 0;
dummy.remove();
......@@ -328,13 +335,13 @@ test("data-* attributes", function() {
ok( obj2[ check[i] ], "Make sure data- property exists when calling data-." );
}
for ( var prop in obj ) {
for ( prop in obj ) {
num++;
}
equal( num, check.length, "Make sure that the right number of properties came through." );
for ( var prop in obj2 ) {
for ( prop in obj2 ) {
num2++;
}
......@@ -397,7 +404,7 @@ test("data-* attributes", function() {
deepEqual(jQuery(elem).data("stuff"), [2,8], "Check stuff property");
break;
default:
ok(false, ["Assertion failed on index ", index, ", with data ", data].join(""));
ok(false, ["Assertion failed on index ", index, ", with data"].join(""));
}
}
......
......@@ -324,16 +324,20 @@ test( "jQuery.when" , function() {
strictEqual( this, context, "when( promise ) propagates context" );
});
var cache, i;
var cache;
jQuery.each([ 1, 2, 3 ], function(k, i) {
for( i = 1 ; i < 4 ; i++ ) {
jQuery.when( cache || jQuery.Deferred( function() {
this.resolve( i );
}) ).done(function( value ) {
strictEqual( value , 1 , "Function executed" + ( i > 1 ? " only once" : "" ) );
this.resolve( i );
})
).done(function( value ) {
strictEqual( value, 1 , "Function executed" + ( i > 1 ? " only once" : "" ) );
cache = value;
});
}
});
});
test("jQuery.when - joined", function() {
......@@ -369,10 +373,10 @@ test("jQuery.when - joined", function() {
shouldError = willError[ id1 ] || willError[ id2 ],
shouldNotify = willNotify[ id1 ] || willNotify[ id2 ],
expected = shouldResolve ? [ 1, 1 ] : [ 0, undefined ],
expectedNotify = shouldNotify && [ willNotify[ id1 ], willNotify[ id2 ] ],
code = id1 + "/" + id2,
context1 = defer1 && jQuery.isFunction( defer1.promise ) ? defer1 : undefined,
context2 = defer2 && jQuery.isFunction( defer2.promise ) ? defer2 : undefined;
expectedNotify = shouldNotify && [ willNotify[ id1 ], willNotify[ id2 ] ],
code = id1 + "/" + id2,
context1 = defer1 && jQuery.isFunction( defer1.promise ) ? defer1 : undefined,
context2 = defer2 && jQuery.isFunction( defer2.promise ) ? defer2 : undefined;
jQuery.when( defer1, defer2 ).done(function( a, b ) {
if ( shouldResolve ) {
......
......@@ -2,13 +2,13 @@ if ( jQuery.fn.width ) {
module("dimensions", { teardown: moduleTeardown });
function pass( val ) {
var pass = function( val ) {
return val;
}
};
function fn( val ) {
var fn = function( val ) {
return function(){ return val; };
}
};
/*
======== local reference =======
......@@ -22,7 +22,7 @@ function fn( val ) {
Returns a function that returns the value
*/
function testWidth( val ) {
var testWidth = function( val ) {
expect(9);
var $div = jQuery("#nothiddendiv");
......@@ -51,7 +51,7 @@ function testWidth( val ) {
equal( jQuery(window).width(), document.documentElement.clientWidth, "Window width is equal to width reported by window/document." );
jQuery.removeData($div[0], "olddisplay", true);
}
};
test("width()", function() {
testWidth( pass );
......@@ -73,7 +73,7 @@ test("width(Function(args))", function() {
equal( $div.width(), 31, "Make sure value was modified correctly." );
});
function testHeight( val ) {
var testHeight = function( val ) {
expect(9);
var $div = jQuery("#nothiddendiv");
......@@ -102,7 +102,7 @@ function testHeight( val ) {
equal( jQuery(window).height(), document.documentElement.clientHeight, "Window width is equal to width reported by window/document." );
jQuery.removeData($div[0], "olddisplay", true);
}
};
test("height()", function() {
testHeight( pass );
......
......@@ -37,7 +37,9 @@ test("show()", function() {
var pass = true;
div = jQuery("#qunit-fixture div");
div.show().each(function(){
if ( this.style.display == "none" ) pass = false;
if ( this.style.display == "none" ) {
pass = false;
}
});
ok( pass, "Show" );
......@@ -50,7 +52,9 @@ test("show()", function() {
jQuery.each(speeds, function(name, speed) {
pass = true;
div.hide().show(speed).each(function() {
if ( this.style.display == "none" ) pass = false;
if ( this.style.display == "none" ) {
pass = false;
}
});
ok( pass, "Show with " + name);
});
......@@ -874,16 +878,16 @@ jQuery.each({
}
var num = 0;
if ( t_h == "show" ) num++;
if ( t_w == "show" ) num++;
if ( t_w == "hide" || t_w == "show" ) num++;
if ( t_h == "hide" || t_h == "show" ) num++;
if ( t_o == "hide" || t_o == "show" ) num++;
if ( t_w == "hide" ) num++;
if ( t_o.constructor == Number ) num += 2;
if ( t_w.constructor == Number ) num += 2;
if ( t_h.constructor == Number ) num +=2;
// TODO: uncrowd this
if ( t_h == "show" ) {num++;}
if ( t_w == "show" ) {num++;}
if ( t_w == "hide" || t_w == "show" ) {num++;}
if ( t_h == "hide" || t_h == "show" ) {num++;}
if ( t_o == "hide" || t_o == "show" ) {num++;}
if ( t_w == "hide" ) {num++;}
if ( t_o.constructor == Number ) {num += 2;}
if ( t_w.constructor == Number ) {num += 2;}
if ( t_h.constructor == Number ) {num +=2;}
expect( num );
stop();
......@@ -935,7 +939,7 @@ jQuery.each({
if ( t_o.constructor == Number ) {
equal( cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o );
ok( jQuery.css(elem, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o );
ok( jQuery.css(elem, "opacity") !== "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o );
}
if ( t_w.constructor == Number ) {
......@@ -943,7 +947,7 @@ jQuery.each({
var cur_w = jQuery.css( elem,"width" );
ok( elem.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w );
ok( elem.style.width !== "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w );
}
if ( t_h.constructor == Number ) {
......@@ -951,7 +955,7 @@ jQuery.each({
var cur_h = jQuery.css( elem,"height" );
ok( elem.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w );
ok( elem.style.height !== "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_h );
}
if ( t_h == "show" ) {
......@@ -1154,17 +1158,17 @@ test("animate with per-property easing", function(){
c: 100
};
jQuery.easing["_test1"] = function(p) {
jQuery.easing._test1 = function(p) {
_test1_called = true;
return p;
};
jQuery.easing["_test2"] = function(p) {
jQuery.easing._test2 = function(p) {
_test2_called = true;
return p;
};
jQuery.easing["_default_test"] = function(p) {
jQuery.easing._default_test = function(p) {
_default_test_called = true;
return p;
};
......@@ -1190,14 +1194,14 @@ test("animate with CSS shorthand properties", function(){
propsBasic = { padding: "10 20 30" },
propsSpecial = { padding: [ "1 2 3", "_special" ] };
jQuery.easing["_default"] = function(p) {
jQuery.easing._default = function(p) {
if ( p >= 1 ) {
_default_count++;
}
return p;
};
jQuery.easing["_special"] = function(p) {
jQuery.easing._special = function(p) {
if ( p >= 1 ) {
_special_count++;
}
......@@ -1222,8 +1226,8 @@ test("animate with CSS shorthand properties", function(){
equal( _special_count, 4, "special easing called for each property" );
jQuery(this).css("padding", "0");
delete jQuery.easing["_default"];
delete jQuery.easing["_special"];
delete jQuery.easing._default;
delete jQuery.easing._special;
start();
});
});
......@@ -1306,7 +1310,7 @@ asyncTest( "callbacks that throw exceptions will be removed (#5684)", function()
}
foo.animate({ height: 1 }, 1, function() {
throw new testException;
throw new testException();
});
// this test thoroughly abuses undocumented methods - please feel free to update
......@@ -1393,7 +1397,7 @@ asyncTest( "Animate Option: step: function( percent, tween )", 1, function() {
}, {
duration: 1,
step: function( value, tween ) {
calls = counter[ tween.prop ] = counter[ tween.prop ] || [];
var calls = counter[ tween.prop ] = counter[ tween.prop ] || [];
calls.push( value );
}
}).queue( function( next ) {
......@@ -1650,7 +1654,7 @@ asyncTest( "animate does not change start value for non-px animation (#7109)", 1
}
}).queue( function( next ) {
var ratio = computed[ 0 ] / actual;
ok( ratio > .9 && ratio < 1.1 , "Starting width was close enough" );
ok( ratio > 0.9 && ratio < 1.1 , "Starting width was close enough" );
next();
start();
});
......
This diff is collapsed.
This diff is collapsed.
......@@ -17,7 +17,7 @@ testIframe("offset/absolute", "absolute", function($, iframe) {
expect(4);
var doc = iframe.document,
tests, forceScroll;
tests, forceScroll;
// force a scroll value on the main window
// this insures that the results will be wrong
......@@ -86,8 +86,8 @@ testIframe("offset/absolute", "absolute", function( jQuery ) {
// test #5781
var offset = jQuery( "#positionTest" ).offset({ top: 10, left: 10 }).offset();
equal( offset.top, 10, "Setting offset on element with position absolute but 'auto' values." )
equal( offset.left, 10, "Setting offset on element with position absolute but 'auto' values." )
equal( offset.top, 10, "Setting offset on element with position absolute but 'auto' values." );
equal( offset.left, 10, "Setting offset on element with position absolute but 'auto' values." );
// set offset
......
......@@ -60,7 +60,7 @@ test("queue(name) passes in the next item in the queue as a parameter", function
equal(++counter, 2, "Next was called");
next();
}).queue("bar", function() {
equal(++counter, 3, "Other queues are not triggered by next()")
equal(++counter, 3, "Other queues are not triggered by next()");
});
div.dequeue("foo");
......@@ -76,12 +76,12 @@ test("queue() passes in the next item in the queue as a parameter to fx queues",
div.queue(function(next) {
equal(++counter, 1, "Dequeueing");
var self = this;
setTimeout(function() { next() }, 500);
setTimeout(function() { next(); }, 500);
}).queue(function(next) {
equal(++counter, 2, "Next was called");
next();
}).queue("bar", function() {
equal(++counter, 3, "Other queues are not triggered by next()")
equal(++counter, 3, "Other queues are not triggered by next()");
});
jQuery.when( div.promise("fx"), div ).done(function() {
......@@ -136,7 +136,7 @@ test("delay()", function() {
test("clearQueue(name) clears the queue", function() {
expect(2);
stop()
stop();
var div = jQuery({});
var counter = 0;
......@@ -286,4 +286,4 @@ if ( jQuery.fn.stop ) {
foo.stop( false, true );
});
} // if ( jQuery.fn.stop )
} // if ( jQuery.fn.stop )
......@@ -12,8 +12,8 @@ test("element - jQuery only", function() {
deepEqual( jQuery("p", jQuery("div")).get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a context." );
deepEqual( jQuery("div").find("p").get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a context." );
ok( jQuery("#length").length, "\<input name=\"length\"\> cannot be found under IE, see #945" );
ok( jQuery("#lengthtest input").length, "\<input name=\"length\"\> cannot be found under IE, see #945" );
ok( jQuery("#length").length, "<input name=\"length\"> cannot be found under IE, see #945" );
ok( jQuery("#lengthtest input").length, "<input name=\"length\"> cannot be found under IE, see #945" );
//#7533
equal( jQuery("<div id=\"A'B~C.D[E]\"><p>foo</p></div>").find("p").length, 1, "Find where context root is a node and has an ID with CSS3 meta characters" );
......
......@@ -256,5 +256,3 @@ testIframeWithCallback( "A background on the testElement does not cause IE8 to c
}
})();
......@@ -202,9 +202,11 @@ test("filter(Selector|undefined)", function() {
test("filter(Function)", function() {
expect(2);
deepEqual( jQuery("#qunit-fixture p").filter(function() { return !jQuery("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
deepEqual( jQuery("#qunit-fixture p").filter(function() {
return !jQuery("a", this).length;
}).get(), q("sndp", "first"), "filter(Function)" );
deepEqual( jQuery("#qunit-fixture p").filter(function(i, elem) { return !jQuery("a", elem).length }).get(), q("sndp", "first"), "filter(Function) using arg" );
deepEqual( jQuery("#qunit-fixture p").filter(function(i, elem) { return !jQuery("a", elem).length; }).get(), q("sndp", "first"), "filter(Function) using arg" );
});
test("filter(Element)", function() {
......@@ -341,7 +343,7 @@ test("not(Element)", function() {
});
test("not(Function)", function() {
deepEqual( jQuery("#qunit-fixture p").not(function() { return jQuery("a", this).length }).get(), q("sndp", "first"), "not(Function)" );
deepEqual( jQuery("#qunit-fixture p").not(function() { return jQuery("a", this).length; }).get(), q("sndp", "first"), "not(Function)" );
});
test("not(Array)", function() {
......@@ -600,15 +602,15 @@ test("add(String|Element|Array|undefined)", function() {
equal( x[0].id, "x1", "Check on-the-fly element1" );
equal( x[1].id, "x2", "Check on-the-fly element2" );
var x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>").appendTo(tmp)[0]).add(jQuery("<p id='x2'>xxx</p>").appendTo(tmp)[0]);
x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>").appendTo(tmp)[0]).add(jQuery("<p id='x2'>xxx</p>").appendTo(tmp)[0]);
equal( x[0].id, "x1", "Check on-the-fly element1" );
equal( x[1].id, "x2", "Check on-the-fly element2" );
var x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>")).add(jQuery("<p id='x2'>xxx</p>"));
x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>")).add(jQuery("<p id='x2'>xxx</p>"));
equal( x[0].id, "x1", "Check on-the-fly element1" );
equal( x[1].id, "x2", "Check on-the-fly element2" );
var x = jQuery([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
x = jQuery([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
equal( x[0].id, "x1", "Check on-the-fly element1" );
equal( x[1].id, "x2", "Check on-the-fly element2" );
......@@ -640,4 +642,3 @@ test("eq('-1') #10616", function() {
equal( $divs.eq( "-1" ).length, 1, "The string '-1' returns a selection that has length 1" );
deepEqual( $divs.eq( "-1" ), $divs.eq( -1 ), "String and number -1 match" );
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment