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 ) { ...@@ -79,7 +79,7 @@ module.exports = function( grunt ) {
"dist/jquery.min.js": [ "<banner>", "dist/jquery.js" ] "dist/jquery.min.js": [ "<banner>", "dist/jquery.js" ]
}, },
lint: { lint: {
files: [ "grunt.js", "dist/jquery.js" ] files: [ "test/unit/**/*.js", "grunt.js", "dist/jquery.js" ]
}, },
qunit: { qunit: {
files: "test/index.html" files: "test/index.html"
...@@ -99,14 +99,12 @@ module.exports = function( grunt ) { ...@@ -99,14 +99,12 @@ module.exports = function( grunt ) {
trailing: true, trailing: true,
undef: true, undef: true,
smarttabs: true, smarttabs: true,
predef: [
"define",
"DOMParser",
"__dirname"
],
maxerr: 100 maxerr: 100
}, },
globals: { globals: {
define: true,
DOMParser: true,
__dirname: true,
jQuery: true, jQuery: true,
global: true, global: true,
module: true, module: true,
...@@ -114,7 +112,37 @@ module.exports = function( grunt ) { ...@@ -114,7 +112,37 @@ module.exports = function( grunt ) {
require: true, require: true,
file: true, file: true,
log: 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: {} uglify: {}
......
...@@ -381,7 +381,7 @@ test(".ajax() - headers" , function() { ...@@ -381,7 +381,7 @@ test(".ajax() - headers" , function() {
headers: requestHeaders, headers: requestHeaders,
success: function( data , _ , xhr ) { success: function( data , _ , xhr ) {
var tmp = []; var tmp = [], i;
for ( i in requestHeaders ) { for ( i in requestHeaders ) {
tmp.push( i , ": " , requestHeaders[ i ] , "\n" ); tmp.push( i , ": " , requestHeaders[ i ] , "\n" );
} }
...@@ -1000,7 +1000,7 @@ test("jQuery.param()", function() { ...@@ -1000,7 +1000,7 @@ test("jQuery.param()", function() {
jQuery.ajaxSetup({ traditional: true }); 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" ); equal( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
params = {someName: [1, 2, 3], regularThing: "blah" }; params = {someName: [1, 2, 3], regularThing: "blah" };
...@@ -1038,10 +1038,13 @@ test("jQuery.param() Constructed prop values", function() { ...@@ -1038,10 +1038,13 @@ test("jQuery.param() Constructed prop values", function() {
this.prop = "val"; 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" ); 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" ); equal( jQuery.param( params, false ), "test=5", "Do not mistake new Number() for a plain object" );
params = { "test": new Date() }; params = { "test": new Date() };
...@@ -1054,14 +1057,20 @@ test("jQuery.param() Constructed prop values", function() { ...@@ -1054,14 +1057,20 @@ test("jQuery.param() Constructed prop values", function() {
test("synchronous request", function() { test("synchronous request", function() {
expect(1); 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() { test("synchronous request with callbacks", function() {
expect(2); expect(2);
var result; var result;
jQuery.ajax({url: url("data/json_obj.js"), async: false, dataType: "text", success: function(data) { ok(true, "sucess callback executed"); result = data; } }); 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() { test("pass-through request object", function() {
...@@ -1113,8 +1122,9 @@ test("ajax cache", function () { ...@@ -1113,8 +1122,9 @@ test("ajax cache", function () {
} }
equal(i, 1, "Test to make sure only one 'no-cache' parameter is there"); 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"); ok(oldOne != "tobereplaced555", "Test to be sure parameter (if it was there) was replaced");
if(++count == 6) if(++count == 6) {
start(); start();
}
}); });
ok( jQuery.ajax({url: "data/text.php", cache:false}), "test with no parameters" ); 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 ) ...@@ -1372,7 +1382,11 @@ jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label )
expect(24); expect(24);
var count = 0; var count = 0;
function plus(){ if ( ++count == 20 ) start(); } function plus(){
if ( ++count == 20 ) {
start();
}
}
stop(); stop();
...@@ -1858,19 +1872,19 @@ test("jQuery.getJSON(String, Function) - JSON object", function() { ...@@ -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); expect(2);
var old = window.JSON; var old = window.JSON;
JSON = {
parse: function(str){ window.JSON = {
parse: function(str) {
ok( true, "Verifying that parse method was run" ); ok( true, "Verifying that parse method was run" );
return true; return true;
} }
}; };
stop(); jQuery.getJSON(url("data/json.php"), function( json ) {
jQuery.getJSON(url("data/json.php"), function(json) {
window.JSON = old; window.JSON = old;
equal( json, true, "Verifying return value" ); equal( json, true, "Verifying return value" );
start(); start();
...@@ -1930,7 +1944,9 @@ test("jQuery.post(String, Hash, Function) - simple with xml", function() { ...@@ -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("calculation", this).text(), "5-2", "Check for XML" );
equal( jQuery("result", this).text(), "3", "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.post(url("data/name.php?xml=5-2"), {}, function(xml){
...@@ -1938,7 +1954,9 @@ test("jQuery.post(String, Hash, Function) - simple with xml", function() { ...@@ -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("calculation", this).text(), "5-2", "Check for XML" );
equal( jQuery("result", this).text(), "3", "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() { ...@@ -2196,14 +2214,22 @@ test("jQuery ajax - failing cross-domain", function() {
url: "http://somewebsitethatdoesnotexist-67864863574657654.com", url: "http://somewebsitethatdoesnotexist-67864863574657654.com",
success: function(){ ok( false , "success" ); }, success: function(){ ok( false , "success" ); },
error: function(xhr,_,e){ ok( true , "file not found: " + xhr.status + " => " + e ); }, error: function(xhr,_,e){ ok( true , "file not found: " + xhr.status + " => " + e ); },
complete: function() { if ( ! --i ) start(); } complete: function() {
if ( ! --i ) {
start();
}
}
}); });
jQuery.ajax({ jQuery.ajax({
url: "http://www.google.com", url: "http://www.google.com",
success: function(){ ok( false , "success" ); }, success: function(){ ok( false , "success" ); },
error: function(xhr,_,e){ ok( true , "access denied: " + xhr.status + " => " + e ); }, 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 ...@@ -2498,7 +2524,7 @@ test( "jQuery.domManip - script in comments are properly evaluated (#11402)", fu
}); });
test("jQuery.ajax - active counter", function() { 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() { ...@@ -156,7 +156,9 @@ test("attr(Hash)", function() {
expect(3); expect(3);
var pass = true; var pass = true;
jQuery("div").attr({foo: "baz", zoo: "ping"}).each(function(){ 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" ); ok( pass, "Set Multiple Attributes" );
equal( jQuery("#text1").attr({value: function() { return this.id; }})[0].value, "text1", "Set attribute to computed value #1" ); 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() { ...@@ -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" ); equal( $radio.val(), "sup", "Value is not reset when type is set after value on a radio" );
// Setting attributes on svg elements (bug #3116) // 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'>" var $svg = jQuery(
+ "<circle cx='200' cy='200' r='150' />" "<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'>" +
+ "</svg>").appendTo("body");
"<circle cx='200' cy='200' r='150' />" +
"</svg>"
).appendTo("body");
equal( $svg.attr("cx", 100).attr("cx"), "100", "Set attribute on svg element" ); equal( $svg.attr("cx", 100).attr("cx"), "100", "Set attribute on svg element" );
$svg.remove(); $svg.remove();
...@@ -811,7 +816,7 @@ var testVal = function(valueObj) { ...@@ -811,7 +816,7 @@ var testVal = function(valueObj) {
j.val(valueObj( "asdf" )); j.val(valueObj( "asdf" ));
equal( j.val(), "asdf", "Check node,textnode,comment with val()" ); equal( j.val(), "asdf", "Check node,textnode,comment with val()" );
j.removeAttr("value"); j.removeAttr("value");
} };
test("val(String/Number)", function() { test("val(String/Number)", function() {
testVal(bareObj); testVal(bareObj);
...@@ -972,7 +977,9 @@ test("addClass(Function) with incoming value", function() { ...@@ -972,7 +977,9 @@ test("addClass(Function) with incoming value", function() {
var pass = true; var pass = true;
for ( var i = 0; i < div.length; i++ ) { 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" ); ok( pass, "Add Class" );
}); });
...@@ -1180,7 +1187,8 @@ test("addClass, removeClass, hasClass", function() { ...@@ -1180,7 +1187,8 @@ test("addClass, removeClass, hasClass", function() {
ok( jq.hasClass("hi"), "Check has1" ); ok( jq.hasClass("hi"), "Check has1" );
ok( jq.hasClass("bar"), "Check has2" ); 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.hasClass("class1"), "Check hasClass with line feed" );
ok( jq.is(".class1"), "Check is with line feed" ); ok( jq.is(".class1"), "Check is with line feed" );
ok( jq.hasClass("class2"), "Check hasClass with tab" ); ok( jq.hasClass("class2"), "Check hasClass with tab" );
...@@ -1190,13 +1198,13 @@ test("addClass, removeClass, hasClass", function() { ...@@ -1190,13 +1198,13 @@ test("addClass, removeClass, hasClass", function() {
ok( jq.is(".class4"), "Check is with carriage return" ); ok( jq.is(".class4"), "Check is with carriage return" );
jq.removeClass("class2"); 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"); jq.removeClass("cla");
ok( jq.hasClass("cla.ss3"), "Check the dotted class has not been removed" ); ok( jq.hasClass("cla.ss3"), "Check the dotted class has not been removed" );
jq.removeClass("cla.ss3"); 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"); 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() { test("contents().hasClass() returns correct values", function() {
......
...@@ -322,10 +322,10 @@ test("type", function() { ...@@ -322,10 +322,10 @@ test("type", function() {
equal( jQuery.type(document.getElementsByTagName("*")), "object", "NodeList" ); equal( jQuery.type(document.getElementsByTagName("*")), "object", "NodeList" );
}); });
test("isPlainObject", function() { asyncTest("isPlainObject", function() {
expect(15); expect(15);
stop(); var iframe;
// The use case that we want to match // The use case that we want to match
ok(jQuery.isPlainObject({}), "{}"); ok(jQuery.isPlainObject({}), "{}");
...@@ -341,7 +341,7 @@ test("isPlainObject", function() { ...@@ -341,7 +341,7 @@ test("isPlainObject", function() {
ok(!jQuery.isPlainObject([]), "array"); ok(!jQuery.isPlainObject([]), "array");
// Instantiated objects shouldn't be matched // Instantiated objects shouldn't be matched
ok(!jQuery.isPlainObject(new Date), "new Date"); ok(!jQuery.isPlainObject(new Date()), "new Date");
var fn = function(){}; var fn = function(){};
...@@ -349,14 +349,14 @@ test("isPlainObject", function() { ...@@ -349,14 +349,14 @@ test("isPlainObject", function() {
ok(!jQuery.isPlainObject(fn), "fn"); ok(!jQuery.isPlainObject(fn), "fn");
// Again, instantiated objects shouldn't be matched // 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 // Makes the function a little more realistic
// (and harder to detect, incidentally) // (and harder to detect, incidentally)
fn.prototype = {someMethod: function(){}}; fn.prototype = {someMethod: function(){}};
// Again, instantiated objects shouldn't be matched // Again, instantiated objects shouldn't be matched
ok(!jQuery.isPlainObject(new fn), "new fn"); ok(!jQuery.isPlainObject(new fn()), "new fn");
// DOM Element // DOM Element
ok(!jQuery.isPlainObject(document.createElement("div")), "DOM Element"); ok(!jQuery.isPlainObject(document.createElement("div")), "DOM Element");
...@@ -372,12 +372,12 @@ test("isPlainObject", function() { ...@@ -372,12 +372,12 @@ test("isPlainObject", function() {
} }
try { try {
var iframe = document.createElement("iframe"); iframe = document.createElement("iframe");
document.body.appendChild(iframe); document.body.appendChild(iframe);
window.iframeDone = function(otherObject){ window.iframeDone = function(otherObject){
// Objects from other windows should be matched // 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 ); document.body.removeChild( iframe );
start(); start();
}; };
...@@ -474,7 +474,7 @@ test("isFunction", function() { ...@@ -474,7 +474,7 @@ test("isFunction", function() {
ok( jQuery.isFunction(fn), "Recursive Function Call" ); ok( jQuery.isFunction(fn), "Recursive Function Call" );
fn({ some: "data" }); fn({ some: "data" });
}; }
callme(function(){ callme(function(){
callme(function(){}); callme(function(){});
...@@ -482,7 +482,7 @@ test("isFunction", function() { ...@@ -482,7 +482,7 @@ test("isFunction", function() {
}); });
test( "isNumeric", function() { test( "isNumeric", function() {
expect( 37 ); expect( 36 );
var t = jQuery.isNumeric, var t = jQuery.isNumeric,
Traditionalists = function(n) { Traditionalists = function(n) {
...@@ -501,7 +501,9 @@ test( "isNumeric", function() { ...@@ -501,7 +501,9 @@ test( "isNumeric", function() {
ok( t(0), "Zero integer number"); ok( t(0), "Zero integer number");
ok( t(32), "Positive integer number"); ok( t(32), "Positive integer number");
ok( t("040"), "Octal integer literal string"); 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("0xFF"), "Hexadecimal integer literal string");
ok( t(0xFFF), "Hexadecimal integer literal"); ok( t(0xFFF), "Hexadecimal integer literal");
ok( t("-1.6"), "Negative floating point string"); ok( t("-1.6"), "Negative floating point string");
...@@ -529,7 +531,7 @@ test( "isNumeric", function() { ...@@ -529,7 +531,7 @@ test( "isNumeric", function() {
equal( t(rong), false, "Custom .toString returning non-number"); equal( t(rong), false, "Custom .toString returning non-number");
equal( t({}), false, "Empty object"); equal( t({}), false, "Empty object");
equal( t(function(){} ), false, "Instance of a function"); 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"); equal( t(function(){} ), false, "Instance of a function");
}); });
...@@ -705,8 +707,8 @@ test("toArray()", function() { ...@@ -705,8 +707,8 @@ test("toArray()", function() {
expect(1); expect(1);
deepEqual( jQuery("#qunit-fixture p").toArray(), deepEqual( jQuery("#qunit-fixture p").toArray(),
q("firstp","ap","sndp","en","sap","first"), q("firstp","ap","sndp","en","sap","first"),
"Convert jQuery object to an Array" ) "Convert jQuery object to an Array" );
}) });
test("inArray()", function() { test("inArray()", function() {
expect(19); expect(19);
...@@ -754,7 +756,7 @@ test("get(-Number)",function() { ...@@ -754,7 +756,7 @@ test("get(-Number)",function() {
expect(2); expect(2);
equal( jQuery("p").get(-1), document.getElementById("first"), "Get a single element with negative index" ); 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" ); strictEqual( jQuery("#firstp").get(-2), undefined, "Try get with index negative index larger then elements count" );
}) });
test("each(Function)", function() { test("each(Function)", function() {
expect(1); expect(1);
...@@ -762,7 +764,9 @@ test("each(Function)", function() { ...@@ -762,7 +764,9 @@ test("each(Function)", function() {
div.each(function(){this.foo = "zoo";}); div.each(function(){this.foo = "zoo";});
var pass = true; var pass = true;
for ( var i = 0; i < div.size(); i++ ) { 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" ); ok( pass, "Execute a function, Relative" );
}); });
...@@ -813,36 +817,37 @@ test("map()", function() { ...@@ -813,36 +817,37 @@ test("map()", function() {
"Single Map" "Single Map"
); );
var keys, values, scripts, nonsense, mapped, flat;
//for #2616 //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; return k;
}); });
equal( keys.join(""), "ab", "Map the keys from a hash to an array" ); 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; return v;
}); });
equal( values.join(""), "12", "Map the values from a hash to an array" ); equal( values.join(""), "12", "Map the values from a hash to an array" );
// object with length prop // 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; return v;
}); });
equal( values.join(""), "123", "Map the values from a hash with a length property to an array" ); equal( values.join(""), "123", "Map the values from a hash with a length property to an array" );
var scripts = document.getElementsByTagName("script"); scripts = document.getElementsByTagName("script");
var mapped = jQuery.map( scripts, function( v, k ){ mapped = jQuery.map( scripts, function( v, k ){
return v; return v;
}); });
equal( mapped.length, scripts.length, "Map an array(-like) to a hash" ); equal( mapped.length, scripts.length, "Map an array(-like) to a hash" );
var nonsense = document.getElementsByTagName("asdf"); nonsense = document.getElementsByTagName("asdf");
var mapped = jQuery.map( nonsense, function( v, k ){ mapped = jQuery.map( nonsense, function( v, k ){
return v; return v;
}); });
equal( mapped.length, nonsense.length, "Map an empty array(-like) to a hash" ); 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 return k % 2 ? k : [k,k,k];//try mixing array and regular returns
}); });
equal( flat.join(""), "00012223", "try the new flatten technique(#2616)" ); equal( flat.join(""), "00012223", "try the new flatten technique(#2616)" );
...@@ -909,7 +914,7 @@ test("jQuery.extend(Object, Object)", function() { ...@@ -909,7 +914,7 @@ test("jQuery.extend(Object, Object)", function() {
deepEqual( empty.foo, optionsWithLength.foo, "The length property must copy correctly" ); deepEqual( empty.foo, optionsWithLength.foo, "The length property must copy correctly" );
empty = {}; empty = {};
var optionsWithDate = { foo: { date: new Date } }; var optionsWithDate = { foo: { date: new Date() } };
jQuery.extend(true, empty, optionsWithDate); jQuery.extend(true, empty, optionsWithDate);
deepEqual( empty.foo, optionsWithDate.foo, "Dates copy correctly" ); deepEqual( empty.foo, optionsWithDate.foo, "Dates copy correctly" );
...@@ -926,7 +931,8 @@ test("jQuery.extend(Object, Object)", function() { ...@@ -926,7 +931,8 @@ test("jQuery.extend(Object, Object)", function() {
jQuery.extend(true, empty, optionsWithCustomObject); jQuery.extend(true, empty, optionsWithCustomObject);
ok( empty.foo && empty.foo.date === customObject, "Custom objects copy correctly" ); 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" ); ok( ret.foo == 5, "Wrapped numbers copy correctly" );
var nullUndef; var nullUndef;
...@@ -944,13 +950,13 @@ test("jQuery.extend(Object, Object)", function() { ...@@ -944,13 +950,13 @@ test("jQuery.extend(Object, Object)", function() {
jQuery.extend(true, target, recursive); 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" ); 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" ); 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" ); 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" ); ok( typeof ret.foo !== "undefined", "Make sure a null value doesn't crash with deep extend, for #1908" );
var obj = { foo:null }; var obj = { foo:null };
...@@ -969,7 +975,7 @@ test("jQuery.extend(Object, Object)", function() { ...@@ -969,7 +975,7 @@ test("jQuery.extend(Object, Object)", function() {
options2Copy = { xstring2: "xx", xxx: "newstringx" }, options2Copy = { xstring2: "xx", xxx: "newstringx" },
merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", 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( settings, merged2, "Check if extended: settings must be extended" );
deepEqual( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" ); deepEqual( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
deepEqual( options1, options1Copy, "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() { ...@@ -994,7 +1000,12 @@ test("jQuery.each(Object,Function)", function() {
jQuery.each([1,2,3], function(i,v){ total += v; }); jQuery.each([1,2,3], function(i,v){ total += v; });
equal( total, 6, "Looping over an array" ); equal( total, 6, "Looping over an array" );
total = 0; 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" ); equal( total, 3, "Looping over an array, with break" );
total = 0; total = 0;
jQuery.each({"a":1,"b":2,"c":3}, function(i,v){ total += v; }); jQuery.each({"a":1,"b":2,"c":3}, function(i,v){ total += v; });
......
...@@ -73,21 +73,21 @@ test("css(String|Hash)", function() { ...@@ -73,21 +73,21 @@ test("css(String|Hash)", function() {
div = jQuery("#nothiddendiv"); div = jQuery("#nothiddendiv");
var child = jQuery("#nothiddendivchild"); var child = jQuery("#nothiddendivchild");
equal( parseInt(div.css("fontSize")), 16, "Verify fontSize px set." ); equal( parseInt(div.css("fontSize"), 10), 16, "Verify fontSize px set." );
equal( parseInt(div.css("font-size")), 16, "Verify fontSize px set." ); equal( parseInt(div.css("font-size"), 10), 16, "Verify fontSize px set." );
equal( parseInt(child.css("fontSize")), 16, "Verify fontSize px set." ); equal( parseInt(child.css("fontSize"), 10), 16, "Verify fontSize px set." );
equal( parseInt(child.css("font-size")), 16, "Verify fontSize px set." ); equal( parseInt(child.css("font-size"), 10), 16, "Verify fontSize px set." );
child.css("height", "100%"); child.css("height", "100%");
equal( child[0].style.height, "100%", "Make sure the height is being set correctly." ); equal( child[0].style.height, "100%", "Make sure the height is being set correctly." );
child.attr("class", "em"); 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 // Have to verify this as the result depends upon the browser's CSS
// support for font-size percentages // support for font-size percentages
child.attr("class", "prct"); 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 ) { if ( prctval === 16 || prctval === 24 ) {
checkval = prctval; checkval = prctval;
} }
...@@ -314,8 +314,8 @@ test("css(String, Function)", function() { ...@@ -314,8 +314,8 @@ test("css(String, Function)", function() {
index = 0; index = 0;
jQuery("#cssFunctionTest div").each(function() { jQuery("#cssFunctionTest div").each(function() {
var computedSize = jQuery(this).css("font-size") var computedSize = jQuery(this).css("font-size");
var expectedSize = sizes[index] var expectedSize = sizes[index];
equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize ); equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++; index++;
}); });
...@@ -344,7 +344,7 @@ test("css(String, Function) with incoming value", function() { ...@@ -344,7 +344,7 @@ test("css(String, Function) with incoming value", function() {
index = 0; index = 0;
jQuery("#cssFunctionTest div").css("font-size", function(i, computedSize) { 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 ); equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++; index++;
return computedSize; return computedSize;
...@@ -374,8 +374,8 @@ test("css(Object) where values are Functions", function() { ...@@ -374,8 +374,8 @@ test("css(Object) where values are Functions", function() {
index = 0; index = 0;
jQuery("#cssFunctionTest div").each(function() { jQuery("#cssFunctionTest div").each(function() {
var computedSize = jQuery(this).css("font-size") var computedSize = jQuery(this).css("font-size");
var expectedSize = sizes[index] var expectedSize = sizes[index];
equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize ); equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++; index++;
}); });
...@@ -404,7 +404,7 @@ test("css(Object) where values are Functions with incoming values", function() { ...@@ -404,7 +404,7 @@ test("css(Object) where values are Functions with incoming values", function() {
index = 0; index = 0;
jQuery("#cssFunctionTest div").css({"font-size": function(i, computedSize) { 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 ); equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++; index++;
return computedSize; return computedSize;
...@@ -444,7 +444,9 @@ test("show(); hide()", function() { ...@@ -444,7 +444,9 @@ test("show(); hide()", function() {
var pass = true; var pass = true;
div = jQuery("#qunit-fixture div"); div = jQuery("#qunit-fixture div");
div.show().each(function(){ div.show().each(function(){
if ( this.style.display == "none" ) pass = false; if ( this.style.display == "none" ) {
pass = false;
}
}); });
ok( pass, "Show" ); ok( pass, "Show" );
...@@ -700,7 +702,7 @@ test("can't get background-position in IE<9, see #10796", function() { ...@@ -700,7 +702,7 @@ test("can't get background-position in IE<9, see #10796", function() {
"12em center", "12em center",
"+12em center", "+12em center",
"12.2em center", "12.2em center",
"center center", "center center"
], ],
l = units.length, l = units.length,
i = 0; i = 0;
......
...@@ -18,10 +18,12 @@ function dataTests (elem) { ...@@ -18,10 +18,12 @@ function dataTests (elem) {
return cacheLength; return cacheLength;
} }
var oldCacheLength, dataObj, internalDataObj, expected, actual;
equal( jQuery.data(elem, "foo"), undefined, "No data exists initially" ); equal( jQuery.data(elem, "foo"), undefined, "No data exists initially" );
strictEqual( jQuery.hasData(elem), false, "jQuery.hasData agrees 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" ); 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" ); strictEqual( jQuery.data(elem), dataObj, "Calling jQuery.data returns the same data object when called multiple times" );
...@@ -52,7 +54,7 @@ function dataTests (elem) { ...@@ -52,7 +54,7 @@ function dataTests (elem) {
equal( jQuery._data(elem, "foo"), "foo2", "Setting internal data works" ); equal( jQuery._data(elem, "foo"), "foo2", "Setting internal data works" );
equal( jQuery.data(elem, "foo"), "foo1", "Setting internal data does not override user data" ); 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" ); ok( internalDataObj, "Internal data object exists" );
notStrictEqual( dataObj, internalDataObj, "Internal data object is not the same as user data object" ); notStrictEqual( dataObj, internalDataObj, "Internal data object is not the same as user data object" );
...@@ -80,14 +82,14 @@ function dataTests (elem) { ...@@ -80,14 +82,14 @@ function dataTests (elem) {
jQuery.removeData( elem, "foo", true ); jQuery.removeData( elem, "foo", true );
if (elem.nodeType) { if (elem.nodeType) {
var oldCacheLength = getCacheLength(); oldCacheLength = getCacheLength();
jQuery.removeData(elem, "foo"); jQuery.removeData(elem, "foo");
equal( getCacheLength(), oldCacheLength - 1, "Removing the last item in the data object destroys it" ); equal( getCacheLength(), oldCacheLength - 1, "Removing the last item in the data object destroys it" );
} }
else { else {
jQuery.removeData(elem, "foo"); jQuery.removeData(elem, "foo");
var expected, actual;
if (jQuery.support.deleteExpando) { if (jQuery.support.deleteExpando) {
expected = false; expected = false;
...@@ -117,7 +119,7 @@ function dataTests (elem) { ...@@ -117,7 +119,7 @@ function dataTests (elem) {
jQuery.removeData(elem, "foo"); jQuery.removeData(elem, "foo");
equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) jQuery.removeData for user data does not remove internal data" ); 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(); oldCacheLength = getCacheLength();
jQuery.removeData(elem, "foo", true); 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" ); 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() { ...@@ -204,9 +206,9 @@ test(".data(String) and .data(String, Object)", function() {
div = parent.children(); div = parent.children();
parent parent
.bind("getData", function(){ ok( false, "getData bubbled." ) }) .bind("getData", function(){ ok( false, "getData bubbled." ); })
.bind("setData", function(){ ok( false, "setData bubbled." ) }) .bind("setData", function(){ ok( false, "setData bubbled." ); })
.bind("changeData", function(){ ok( false, "changeData bubbled." ) }); .bind("changeData", function(){ ok( false, "changeData bubbled." ); });
ok( div.data("test") === undefined, "Check for no data exists" ); ok( div.data("test") === undefined, "Check for no data exists" );
...@@ -319,7 +321,12 @@ test("data-* attributes", function() { ...@@ -319,7 +321,12 @@ test("data-* attributes", function() {
child.data("ignored", "cache"); child.data("ignored", "cache");
equal( child.data("ignored"), "cache", "Cached data used before DOM data-* fallback"); 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(); dummy.remove();
...@@ -328,13 +335,13 @@ test("data-* attributes", function() { ...@@ -328,13 +335,13 @@ test("data-* attributes", function() {
ok( obj2[ check[i] ], "Make sure data- property exists when calling data-." ); ok( obj2[ check[i] ], "Make sure data- property exists when calling data-." );
} }
for ( var prop in obj ) { for ( prop in obj ) {
num++; num++;
} }
equal( num, check.length, "Make sure that the right number of properties came through." ); equal( num, check.length, "Make sure that the right number of properties came through." );
for ( var prop in obj2 ) { for ( prop in obj2 ) {
num2++; num2++;
} }
...@@ -397,7 +404,7 @@ test("data-* attributes", function() { ...@@ -397,7 +404,7 @@ test("data-* attributes", function() {
deepEqual(jQuery(elem).data("stuff"), [2,8], "Check stuff property"); deepEqual(jQuery(elem).data("stuff"), [2,8], "Check stuff property");
break; break;
default: 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() { ...@@ -324,16 +324,20 @@ test( "jQuery.when" , function() {
strictEqual( this, context, "when( promise ) propagates context" ); 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() { jQuery.when( cache || jQuery.Deferred( function() {
this.resolve( i ); this.resolve( i );
}) ).done(function( value ) { })
strictEqual( value , 1 , "Function executed" + ( i > 1 ? " only once" : "" ) ); ).done(function( value ) {
strictEqual( value, 1 , "Function executed" + ( i > 1 ? " only once" : "" ) );
cache = value; cache = value;
}); });
}
});
}); });
test("jQuery.when - joined", function() { test("jQuery.when - joined", function() {
......
...@@ -2,13 +2,13 @@ if ( jQuery.fn.width ) { ...@@ -2,13 +2,13 @@ if ( jQuery.fn.width ) {
module("dimensions", { teardown: moduleTeardown }); module("dimensions", { teardown: moduleTeardown });
function pass( val ) { var pass = function( val ) {
return val; return val;
} };
function fn( val ) { var fn = function( val ) {
return function(){ return val; }; return function(){ return val; };
} };
/* /*
======== local reference ======= ======== local reference =======
...@@ -22,7 +22,7 @@ function fn( val ) { ...@@ -22,7 +22,7 @@ function fn( val ) {
Returns a function that returns the value Returns a function that returns the value
*/ */
function testWidth( val ) { var testWidth = function( val ) {
expect(9); expect(9);
var $div = jQuery("#nothiddendiv"); var $div = jQuery("#nothiddendiv");
...@@ -51,7 +51,7 @@ function testWidth( val ) { ...@@ -51,7 +51,7 @@ function testWidth( val ) {
equal( jQuery(window).width(), document.documentElement.clientWidth, "Window width is equal to width reported by window/document." ); equal( jQuery(window).width(), document.documentElement.clientWidth, "Window width is equal to width reported by window/document." );
jQuery.removeData($div[0], "olddisplay", true); jQuery.removeData($div[0], "olddisplay", true);
} };
test("width()", function() { test("width()", function() {
testWidth( pass ); testWidth( pass );
...@@ -73,7 +73,7 @@ test("width(Function(args))", function() { ...@@ -73,7 +73,7 @@ test("width(Function(args))", function() {
equal( $div.width(), 31, "Make sure value was modified correctly." ); equal( $div.width(), 31, "Make sure value was modified correctly." );
}); });
function testHeight( val ) { var testHeight = function( val ) {
expect(9); expect(9);
var $div = jQuery("#nothiddendiv"); var $div = jQuery("#nothiddendiv");
...@@ -102,7 +102,7 @@ function testHeight( val ) { ...@@ -102,7 +102,7 @@ function testHeight( val ) {
equal( jQuery(window).height(), document.documentElement.clientHeight, "Window width is equal to width reported by window/document." ); equal( jQuery(window).height(), document.documentElement.clientHeight, "Window width is equal to width reported by window/document." );
jQuery.removeData($div[0], "olddisplay", true); jQuery.removeData($div[0], "olddisplay", true);
} };
test("height()", function() { test("height()", function() {
testHeight( pass ); testHeight( pass );
......
...@@ -37,7 +37,9 @@ test("show()", function() { ...@@ -37,7 +37,9 @@ test("show()", function() {
var pass = true; var pass = true;
div = jQuery("#qunit-fixture div"); div = jQuery("#qunit-fixture div");
div.show().each(function(){ div.show().each(function(){
if ( this.style.display == "none" ) pass = false; if ( this.style.display == "none" ) {
pass = false;
}
}); });
ok( pass, "Show" ); ok( pass, "Show" );
...@@ -50,7 +52,9 @@ test("show()", function() { ...@@ -50,7 +52,9 @@ test("show()", function() {
jQuery.each(speeds, function(name, speed) { jQuery.each(speeds, function(name, speed) {
pass = true; pass = true;
div.hide().show(speed).each(function() { 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); ok( pass, "Show with " + name);
}); });
...@@ -874,16 +878,16 @@ jQuery.each({ ...@@ -874,16 +878,16 @@ jQuery.each({
} }
var num = 0; var num = 0;
// TODO: uncrowd this
if ( t_h == "show" ) num++; if ( t_h == "show" ) {num++;}
if ( t_w == "show" ) num++; if ( t_w == "show" ) {num++;}
if ( t_w == "hide" || t_w == "show" ) num++; if ( t_w == "hide" || t_w == "show" ) {num++;}
if ( t_h == "hide" || t_h == "show" ) num++; if ( t_h == "hide" || t_h == "show" ) {num++;}
if ( t_o == "hide" || t_o == "show" ) num++; if ( t_o == "hide" || t_o == "show" ) {num++;}
if ( t_w == "hide" ) num++; if ( t_w == "hide" ) {num++;}
if ( t_o.constructor == Number ) num += 2; if ( t_o.constructor == Number ) {num += 2;}
if ( t_w.constructor == Number ) num += 2; if ( t_w.constructor == Number ) {num += 2;}
if ( t_h.constructor == Number ) num +=2; if ( t_h.constructor == Number ) {num +=2;}
expect( num ); expect( num );
stop(); stop();
...@@ -935,7 +939,7 @@ jQuery.each({ ...@@ -935,7 +939,7 @@ jQuery.each({
if ( t_o.constructor == Number ) { if ( t_o.constructor == Number ) {
equal( cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o ); 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 ) { if ( t_w.constructor == Number ) {
...@@ -943,7 +947,7 @@ jQuery.each({ ...@@ -943,7 +947,7 @@ jQuery.each({
var cur_w = jQuery.css( elem,"width" ); 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 ) { if ( t_h.constructor == Number ) {
...@@ -951,7 +955,7 @@ jQuery.each({ ...@@ -951,7 +955,7 @@ jQuery.each({
var cur_h = jQuery.css( elem,"height" ); 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" ) { if ( t_h == "show" ) {
...@@ -1154,17 +1158,17 @@ test("animate with per-property easing", function(){ ...@@ -1154,17 +1158,17 @@ test("animate with per-property easing", function(){
c: 100 c: 100
}; };
jQuery.easing["_test1"] = function(p) { jQuery.easing._test1 = function(p) {
_test1_called = true; _test1_called = true;
return p; return p;
}; };
jQuery.easing["_test2"] = function(p) { jQuery.easing._test2 = function(p) {
_test2_called = true; _test2_called = true;
return p; return p;
}; };
jQuery.easing["_default_test"] = function(p) { jQuery.easing._default_test = function(p) {
_default_test_called = true; _default_test_called = true;
return p; return p;
}; };
...@@ -1190,14 +1194,14 @@ test("animate with CSS shorthand properties", function(){ ...@@ -1190,14 +1194,14 @@ test("animate with CSS shorthand properties", function(){
propsBasic = { padding: "10 20 30" }, propsBasic = { padding: "10 20 30" },
propsSpecial = { padding: [ "1 2 3", "_special" ] }; propsSpecial = { padding: [ "1 2 3", "_special" ] };
jQuery.easing["_default"] = function(p) { jQuery.easing._default = function(p) {
if ( p >= 1 ) { if ( p >= 1 ) {
_default_count++; _default_count++;
} }
return p; return p;
}; };
jQuery.easing["_special"] = function(p) { jQuery.easing._special = function(p) {
if ( p >= 1 ) { if ( p >= 1 ) {
_special_count++; _special_count++;
} }
...@@ -1222,8 +1226,8 @@ test("animate with CSS shorthand properties", function(){ ...@@ -1222,8 +1226,8 @@ test("animate with CSS shorthand properties", function(){
equal( _special_count, 4, "special easing called for each property" ); equal( _special_count, 4, "special easing called for each property" );
jQuery(this).css("padding", "0"); jQuery(this).css("padding", "0");
delete jQuery.easing["_default"]; delete jQuery.easing._default;
delete jQuery.easing["_special"]; delete jQuery.easing._special;
start(); start();
}); });
}); });
...@@ -1306,7 +1310,7 @@ asyncTest( "callbacks that throw exceptions will be removed (#5684)", function() ...@@ -1306,7 +1310,7 @@ asyncTest( "callbacks that throw exceptions will be removed (#5684)", function()
} }
foo.animate({ height: 1 }, 1, function() { foo.animate({ height: 1 }, 1, function() {
throw new testException; throw new testException();
}); });
// this test thoroughly abuses undocumented methods - please feel free to update // this test thoroughly abuses undocumented methods - please feel free to update
...@@ -1393,7 +1397,7 @@ asyncTest( "Animate Option: step: function( percent, tween )", 1, function() { ...@@ -1393,7 +1397,7 @@ asyncTest( "Animate Option: step: function( percent, tween )", 1, function() {
}, { }, {
duration: 1, duration: 1,
step: function( value, tween ) { step: function( value, tween ) {
calls = counter[ tween.prop ] = counter[ tween.prop ] || []; var calls = counter[ tween.prop ] = counter[ tween.prop ] || [];
calls.push( value ); calls.push( value );
} }
}).queue( function( next ) { }).queue( function( next ) {
...@@ -1650,7 +1654,7 @@ asyncTest( "animate does not change start value for non-px animation (#7109)", 1 ...@@ -1650,7 +1654,7 @@ asyncTest( "animate does not change start value for non-px animation (#7109)", 1
} }
}).queue( function( next ) { }).queue( function( next ) {
var ratio = computed[ 0 ] / actual; 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(); next();
start(); start();
}); });
......
...@@ -104,10 +104,13 @@ test("bind(), multiple events at once", function() { ...@@ -104,10 +104,13 @@ test("bind(), multiple events at once", function() {
var clickCounter = 0, var clickCounter = 0,
mouseoverCounter = 0; mouseoverCounter = 0;
var handler = function(event) { var handler = function(event) {
if (event.type == "click") if (event.type == "click") {
clickCounter += 1; clickCounter += 1;
else if (event.type == "mouseover") }
else if (event.type == "mouseover") {
mouseoverCounter += 1; mouseoverCounter += 1;
}
}; };
jQuery("#firstp").bind("click mouseover", handler).trigger("click").trigger("mouseover"); jQuery("#firstp").bind("click mouseover", handler).trigger("click").trigger("mouseover");
equal( clickCounter, 1, "bind() with multiple events at once" ); equal( clickCounter, 1, "bind() with multiple events at once" );
...@@ -250,18 +253,24 @@ test("bind/one/unbind(Object)", function(){ ...@@ -250,18 +253,24 @@ test("bind/one/unbind(Object)", function(){
var clickCounter = 0, mouseoverCounter = 0; var clickCounter = 0, mouseoverCounter = 0;
function handler(event) { function handler(event) {
if (event.type == "click") if (event.type == "click") {
clickCounter++; clickCounter++;
else if (event.type == "mouseover") }
else if (event.type == "mouseover") {
mouseoverCounter++; mouseoverCounter++;
}; }
}
function handlerWithData(event) { function handlerWithData(event) {
if (event.type == "click") if (event.type == "click") {
clickCounter += event.data; clickCounter += event.data;
else if (event.type == "mouseover") }
else if (event.type == "mouseover") {
mouseoverCounter += event.data; mouseoverCounter += event.data;
}; }
}
function trigger(){ function trigger(){
$elem.trigger("click").trigger("mouseover"); $elem.trigger("click").trigger("mouseover");
...@@ -424,7 +433,7 @@ test("bind(), trigger change on select", function() { ...@@ -424,7 +433,7 @@ test("bind(), trigger change on select", function() {
var counter = 0; var counter = 0;
function selectOnChange(event) { function selectOnChange(event) {
equal( event.data, counter++, "Event.data is not a global event object" ); equal( event.data, counter++, "Event.data is not a global event object" );
}; }
jQuery("#form select").each(function(i){ jQuery("#form select").each(function(i){
jQuery(this).bind("change", i, selectOnChange); jQuery(this).bind("change", i, selectOnChange);
}).trigger("change"); }).trigger("change");
...@@ -541,7 +550,7 @@ test("bind(), multi-namespaced events", function() { ...@@ -541,7 +550,7 @@ test("bind(), multi-namespaced events", function() {
}); });
test("bind(), with same function", function() { test("bind(), with same function", function() {
expect(2) expect(2);
var count = 0, func = function(){ var count = 0, func = function(){
count++; count++;
...@@ -563,13 +572,14 @@ test("bind(), make sure order is maintained", function() { ...@@ -563,13 +572,14 @@ test("bind(), make sure order is maintained", function() {
var elem = jQuery("#firstp"), log = [], check = []; var elem = jQuery("#firstp"), log = [], check = [];
for ( var i = 0; i < 100; i++ ) (function(i){ jQuery.each( new Array(100), function( i ) {
elem.bind( "click", function(){ elem.bind( "click", function(){
log.push( i ); log.push( i );
}); });
check.push( i ); check.push( i );
})(i);
});
elem.trigger("click"); elem.trigger("click");
...@@ -768,7 +778,7 @@ test("unbind(eventObject)", function() { ...@@ -768,7 +778,7 @@ test("unbind(eventObject)", function() {
num += 1; num += 1;
}) })
.bind("foo", function(e){ .bind("foo", function(e){
$elem.unbind( e ) $elem.unbind( e );
num += 2; num += 2;
}) })
// Neither this one // Neither this one
...@@ -1153,7 +1163,7 @@ test("trigger(eventObject, [data], [fn])", function() { ...@@ -1153,7 +1163,7 @@ test("trigger(eventObject, [data], [fn])", function() {
event.stopPropagation(); event.stopPropagation();
equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" ); equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
event.isPropagationStopped = function(){ return false }; event.isPropagationStopped = function(){ return false; };
event.stopImmediatePropagation(); event.stopImmediatePropagation();
equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" ); equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
equal( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" ); equal( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" );
...@@ -1213,7 +1223,7 @@ test("trigger(eventObject, [data], [fn])", function() { ...@@ -1213,7 +1223,7 @@ test("trigger(eventObject, [data], [fn])", function() {
$parent.unbind().remove(); $parent.unbind().remove();
// Ensure triggerHandler doesn't molest its event object (#xxx) // Ensure triggerHandler doesn't molest its event object (#xxx)
var event = jQuery.Event( "zowie" ); event = jQuery.Event( "zowie" );
jQuery( document ).triggerHandler( event ); jQuery( document ).triggerHandler( event );
equal( event.type, "zowie", "Verify its type" ); equal( event.type, "zowie", "Verify its type" );
equal( event.isPropagationStopped(), false, "propagation not stopped" ); equal( event.isPropagationStopped(), false, "propagation not stopped" );
...@@ -1419,13 +1429,13 @@ test("toggle(Function, Function, ...)", function() { ...@@ -1419,13 +1429,13 @@ test("toggle(Function, Function, ...)", function() {
var count = 0, var count = 0,
fn1 = function(e) { count++; }, fn1 = function(e) { count++; },
fn2 = function(e) { count--; }, fn2 = function(e) { count--; },
preventDefault = function(e) { e.preventDefault() }, preventDefault = function(e) { e.preventDefault(); },
link = jQuery("#mark"); link = jQuery("#mark");
link.click(preventDefault).click().toggle(fn1, fn2).click().click().click().click().click(); link.click(preventDefault).click().toggle(fn1, fn2).click().click().click().click().click();
equal( count, 1, "Check for toggle(fn, fn)" ); equal( count, 1, "Check for toggle(fn, fn)" );
jQuery("#firstp").toggle(function () { jQuery("#firstp").toggle(function () {
equal(arguments.length, 4, "toggle correctly passes through additional triggered arguments, see #1701" ) equal(arguments.length, 4, "toggle correctly passes through additional triggered arguments, see #1701" );
}, function() {}).trigger("click", [ 1, 2, 3 ]); }, function() {}).trigger("click", [ 1, 2, 3 ]);
var first = 0; var first = 0;
...@@ -1509,7 +1519,7 @@ test(".live()/.die()", function() { ...@@ -1509,7 +1519,7 @@ test(".live()/.die()", function() {
equal( liveb, 0, "Click on body" ); equal( liveb, 0, "Click on body" );
// This should trigger two events // This should trigger two events
submit = 0, div = 0, livea = 0, liveb = 0; submit = 0; div = 0; livea = 0; liveb = 0;
jQuery("div#nothiddendiv").trigger("click"); jQuery("div#nothiddendiv").trigger("click");
equal( submit, 0, "Click on div" ); equal( submit, 0, "Click on div" );
equal( div, 1, "Click on div" ); equal( div, 1, "Click on div" );
...@@ -1517,7 +1527,7 @@ test(".live()/.die()", function() { ...@@ -1517,7 +1527,7 @@ test(".live()/.die()", function() {
equal( liveb, 0, "Click on div" ); equal( liveb, 0, "Click on div" );
// This should trigger three events (w/ bubbling) // This should trigger three events (w/ bubbling)
submit = 0, div = 0, livea = 0, liveb = 0; submit = 0; div = 0; livea = 0; liveb = 0;
jQuery("div#nothiddendivchild").trigger("click"); jQuery("div#nothiddendivchild").trigger("click");
equal( submit, 0, "Click on inner div" ); equal( submit, 0, "Click on inner div" );
equal( div, 2, "Click on inner div" ); equal( div, 2, "Click on inner div" );
...@@ -1525,7 +1535,7 @@ test(".live()/.die()", function() { ...@@ -1525,7 +1535,7 @@ test(".live()/.die()", function() {
equal( liveb, 1, "Click on inner div" ); equal( liveb, 1, "Click on inner div" );
// This should trigger one submit // This should trigger one submit
submit = 0, div = 0, livea = 0, liveb = 0; submit = 0; div = 0; livea = 0; liveb = 0;
jQuery("div#nothiddendivchild").trigger("submit"); jQuery("div#nothiddendivchild").trigger("submit");
equal( submit, 1, "Submit on div" ); equal( submit, 1, "Submit on div" );
equal( div, 0, "Submit on div" ); equal( div, 0, "Submit on div" );
...@@ -1533,7 +1543,7 @@ test(".live()/.die()", function() { ...@@ -1533,7 +1543,7 @@ test(".live()/.die()", function() {
equal( liveb, 0, "Submit on div" ); equal( liveb, 0, "Submit on div" );
// Make sure no other events were removed in the process // Make sure no other events were removed in the process
submit = 0, div = 0, livea = 0, liveb = 0; submit = 0; div = 0; livea = 0; liveb = 0;
jQuery("div#nothiddendivchild").trigger("click"); jQuery("div#nothiddendivchild").trigger("click");
equal( submit, 0, "die Click on inner div" ); equal( submit, 0, "die Click on inner div" );
equal( div, 2, "die Click on inner div" ); equal( div, 2, "die Click on inner div" );
...@@ -1541,7 +1551,7 @@ test(".live()/.die()", function() { ...@@ -1541,7 +1551,7 @@ test(".live()/.die()", function() {
equal( liveb, 1, "die Click on inner div" ); equal( liveb, 1, "die Click on inner div" );
// Now make sure that the removal works // Now make sure that the removal works
submit = 0, div = 0, livea = 0, liveb = 0; submit = 0; div = 0; livea = 0; liveb = 0;
jQuery("div#nothiddendivchild").die("click"); jQuery("div#nothiddendivchild").die("click");
jQuery("div#nothiddendivchild").trigger("click"); jQuery("div#nothiddendivchild").trigger("click");
equal( submit, 0, "die Click on inner div" ); equal( submit, 0, "die Click on inner div" );
...@@ -1550,7 +1560,7 @@ test(".live()/.die()", function() { ...@@ -1550,7 +1560,7 @@ test(".live()/.die()", function() {
equal( liveb, 0, "die Click on inner div" ); equal( liveb, 0, "die Click on inner div" );
// Make sure that the click wasn't removed too early // Make sure that the click wasn't removed too early
submit = 0, div = 0, livea = 0, liveb = 0; submit = 0; div = 0; livea = 0; liveb = 0;
jQuery("div#nothiddendiv").trigger("click"); jQuery("div#nothiddendiv").trigger("click");
equal( submit, 0, "die Click on inner div" ); equal( submit, 0, "die Click on inner div" );
equal( div, 1, "die Click on inner div" ); equal( div, 1, "die Click on inner div" );
...@@ -1558,7 +1568,7 @@ test(".live()/.die()", function() { ...@@ -1558,7 +1568,7 @@ test(".live()/.die()", function() {
equal( liveb, 0, "die Click on inner div" ); equal( liveb, 0, "die Click on inner div" );
// Make sure that stopPropgation doesn't stop live events // Make sure that stopPropgation doesn't stop live events
submit = 0, div = 0, livea = 0, liveb = 0; submit = 0; div = 0; livea = 0; liveb = 0;
jQuery("div#nothiddendivchild").live("click", function(e){ liveb++; e.stopPropagation(); }); jQuery("div#nothiddendivchild").live("click", function(e){ liveb++; e.stopPropagation(); });
jQuery("div#nothiddendivchild").trigger("click"); jQuery("div#nothiddendivchild").trigger("click");
equal( submit, 0, "stopPropagation Click on inner div" ); equal( submit, 0, "stopPropagation Click on inner div" );
...@@ -1567,7 +1577,7 @@ test(".live()/.die()", function() { ...@@ -1567,7 +1577,7 @@ test(".live()/.die()", function() {
equal( liveb, 1, "stopPropagation Click on inner div" ); equal( liveb, 1, "stopPropagation Click on inner div" );
// Make sure click events only fire with primary click // Make sure click events only fire with primary click
submit = 0, div = 0, livea = 0, liveb = 0; submit = 0; div = 0; livea = 0; liveb = 0;
var event = jQuery.Event("click"); var event = jQuery.Event("click");
event.button = 1; event.button = 1;
jQuery("div#nothiddendiv").trigger(event); jQuery("div#nothiddendiv").trigger(event);
...@@ -1609,7 +1619,7 @@ test(".live()/.die()", function() { ...@@ -1609,7 +1619,7 @@ test(".live()/.die()", function() {
jQuery("#foo").live("click", true, jQuery.proxy(function(e, data){ jQuery("#foo").live("click", true, jQuery.proxy(function(e, data){
equal( e.data, true, "live with with different this object, event data, and trigger data" ); equal( e.data, true, "live with with different this object, event data, and trigger data" );
equal( this.foo, "bar", "live with with different this object, event data, and trigger data" ); equal( this.foo, "bar", "live with with different this object, event data, and trigger data" );
equal( data, true, "live with with different this object, event data, and trigger data") equal( data, true, "live with with different this object, event data, and trigger data");
}, { foo: "bar" })); }, { foo: "bar" }));
jQuery("#foo").trigger("click", true).die("click"); jQuery("#foo").trigger("click", true).die("click");
...@@ -1622,7 +1632,7 @@ test(".live()/.die()", function() { ...@@ -1622,7 +1632,7 @@ test(".live()/.die()", function() {
// Verify that .preventDefault() prevents default action // Verify that .preventDefault() prevents default action
jQuery("#anchor2").live("click", function(e){ e.preventDefault(); }); jQuery("#anchor2").live("click", function(e){ e.preventDefault(); });
var hash = window.location.hash; hash = window.location.hash;
jQuery("#anchor2").trigger("click"); jQuery("#anchor2").trigger("click");
equal( window.location.hash, hash, "e.preventDefault() worked" ); equal( window.location.hash, hash, "e.preventDefault() worked" );
jQuery("#anchor2").die("click"); jQuery("#anchor2").die("click");
...@@ -1707,7 +1717,7 @@ test(".live()/.die()", function() { ...@@ -1707,7 +1717,7 @@ test(".live()/.die()", function() {
equal( livee, 0, "Verify that second handler doesn't." ); equal( livee, 0, "Verify that second handler doesn't." );
// Cleanup // Cleanup
jQuery("span#liveSpan1 a").die("click") jQuery("span#liveSpan1 a").die("click");
jQuery("span#liveSpan1").die("click"); jQuery("span#liveSpan1").die("click");
jQuery("span#liveSpan2 a").die("click"); jQuery("span#liveSpan2 a").die("click");
jQuery("span#liveSpan2").die("click"); jQuery("span#liveSpan2").die("click");
...@@ -1822,14 +1832,14 @@ test("live with namespaces", function(){ ...@@ -1822,14 +1832,14 @@ test("live with namespaces", function(){
equal( count1, 1, "Got live foo.bar" ); equal( count1, 1, "Got live foo.bar" );
equal( count2, 0, "Got live foo.bar" ); equal( count2, 0, "Got live foo.bar" );
count1 = 0, count2 = 0; count1 = 0; count2 = 0;
jQuery("#liveSpan1").trigger("foo.zed"); jQuery("#liveSpan1").trigger("foo.zed");
equal( count1, 0, "Got live foo.zed" ); equal( count1, 0, "Got live foo.zed" );
equal( count2, 1, "Got live foo.zed" ); equal( count2, 1, "Got live foo.zed" );
//remove one //remove one
count1 = 0, count2 = 0; count1 = 0; count2 = 0;
jQuery("#liveSpan1").die("foo.zed"); jQuery("#liveSpan1").die("foo.zed");
jQuery("#liveSpan1").trigger("foo.bar"); jQuery("#liveSpan1").trigger("foo.bar");
...@@ -1837,7 +1847,7 @@ test("live with namespaces", function(){ ...@@ -1837,7 +1847,7 @@ test("live with namespaces", function(){
equal( count1, 1, "Got live foo.bar after dieing foo.zed" ); equal( count1, 1, "Got live foo.bar after dieing foo.zed" );
equal( count2, 0, "Got live foo.bar after dieing foo.zed" ); equal( count2, 0, "Got live foo.bar after dieing foo.zed" );
count1 = 0, count2 = 0; count1 = 0; count2 = 0;
jQuery("#liveSpan1").trigger("foo.zed"); jQuery("#liveSpan1").trigger("foo.zed");
equal( count1, 0, "Got live foo.zed" ); equal( count1, 0, "Got live foo.zed" );
...@@ -1846,7 +1856,7 @@ test("live with namespaces", function(){ ...@@ -1846,7 +1856,7 @@ test("live with namespaces", function(){
//remove the other //remove the other
jQuery("#liveSpan1").die("foo.bar"); jQuery("#liveSpan1").die("foo.bar");
count1 = 0, count2 = 0; count1 = 0; count2 = 0;
jQuery("#liveSpan1").trigger("foo.bar"); jQuery("#liveSpan1").trigger("foo.bar");
equal( count1, 0, "Did not respond to foo.bar after dieing it" ); equal( count1, 0, "Did not respond to foo.bar after dieing it" );
...@@ -1862,7 +1872,7 @@ test("live with change", function(){ ...@@ -1862,7 +1872,7 @@ test("live with change", function(){
var selectChange = 0, checkboxChange = 0; var selectChange = 0, checkboxChange = 0;
var select = jQuery("select[name='S1']") var select = jQuery("select[name='S1']");
select.live("change", function() { select.live("change", function() {
selectChange++; selectChange++;
}); });
...@@ -1870,7 +1880,7 @@ test("live with change", function(){ ...@@ -1870,7 +1880,7 @@ test("live with change", function(){
var checkbox = jQuery("#check2"), var checkbox = jQuery("#check2"),
checkboxFunction = function(){ checkboxFunction = function(){
checkboxChange++; checkboxChange++;
} };
checkbox.live("change", checkboxFunction); checkbox.live("change", checkboxFunction);
// test click on select // test click on select
...@@ -2040,7 +2050,7 @@ test(".delegate()/.undelegate()", function() { ...@@ -2040,7 +2050,7 @@ test(".delegate()/.undelegate()", function() {
equal( liveb, 0, "Click on body" ); equal( liveb, 0, "Click on body" );
// This should trigger two events // This should trigger two events
submit = 0, div = 0, livea = 0, liveb = 0; submit = 0; div = 0; livea = 0; liveb = 0;
jQuery("div#nothiddendiv").trigger("click"); jQuery("div#nothiddendiv").trigger("click");
equal( submit, 0, "Click on div" ); equal( submit, 0, "Click on div" );
equal( div, 1, "Click on div" ); equal( div, 1, "Click on div" );
...@@ -2048,7 +2058,7 @@ test(".delegate()/.undelegate()", function() { ...@@ -2048,7 +2058,7 @@ test(".delegate()/.undelegate()", function() {
equal( liveb, 0, "Click on div" ); equal( liveb, 0, "Click on div" );
// This should trigger three events (w/ bubbling) // This should trigger three events (w/ bubbling)
submit = 0, div = 0, livea = 0, liveb = 0; submit = 0; div = 0; livea = 0; liveb = 0;
jQuery("div#nothiddendivchild").trigger("click"); jQuery("div#nothiddendivchild").trigger("click");
equal( submit, 0, "Click on inner div" ); equal( submit, 0, "Click on inner div" );
equal( div, 2, "Click on inner div" ); equal( div, 2, "Click on inner div" );
...@@ -2056,7 +2066,7 @@ test(".delegate()/.undelegate()", function() { ...@@ -2056,7 +2066,7 @@ test(".delegate()/.undelegate()", function() {
equal( liveb, 1, "Click on inner div" ); equal( liveb, 1, "Click on inner div" );
// This should trigger one submit // This should trigger one submit
submit = 0, div = 0, livea = 0, liveb = 0; submit = 0; div = 0; livea = 0; liveb = 0;
jQuery("div#nothiddendivchild").trigger("submit"); jQuery("div#nothiddendivchild").trigger("submit");
equal( submit, 1, "Submit on div" ); equal( submit, 1, "Submit on div" );
equal( div, 0, "Submit on div" ); equal( div, 0, "Submit on div" );
...@@ -2064,7 +2074,7 @@ test(".delegate()/.undelegate()", function() { ...@@ -2064,7 +2074,7 @@ test(".delegate()/.undelegate()", function() {
equal( liveb, 0, "Submit on div" ); equal( liveb, 0, "Submit on div" );
// Make sure no other events were removed in the process // Make sure no other events were removed in the process
submit = 0, div = 0, livea = 0, liveb = 0; submit = 0; div = 0; livea = 0; liveb = 0;
jQuery("div#nothiddendivchild").trigger("click"); jQuery("div#nothiddendivchild").trigger("click");
equal( submit, 0, "undelegate Click on inner div" ); equal( submit, 0, "undelegate Click on inner div" );
equal( div, 2, "undelegate Click on inner div" ); equal( div, 2, "undelegate Click on inner div" );
...@@ -2072,7 +2082,7 @@ test(".delegate()/.undelegate()", function() { ...@@ -2072,7 +2082,7 @@ test(".delegate()/.undelegate()", function() {
equal( liveb, 1, "undelegate Click on inner div" ); equal( liveb, 1, "undelegate Click on inner div" );
// Now make sure that the removal works // Now make sure that the removal works
submit = 0, div = 0, livea = 0, liveb = 0; submit = 0; div = 0; livea = 0; liveb = 0;
jQuery("#body").undelegate("div#nothiddendivchild", "click"); jQuery("#body").undelegate("div#nothiddendivchild", "click");
jQuery("div#nothiddendivchild").trigger("click"); jQuery("div#nothiddendivchild").trigger("click");
equal( submit, 0, "undelegate Click on inner div" ); equal( submit, 0, "undelegate Click on inner div" );
...@@ -2081,7 +2091,7 @@ test(".delegate()/.undelegate()", function() { ...@@ -2081,7 +2091,7 @@ test(".delegate()/.undelegate()", function() {
equal( liveb, 0, "undelegate Click on inner div" ); equal( liveb, 0, "undelegate Click on inner div" );
// Make sure that the click wasn't removed too early // Make sure that the click wasn't removed too early
submit = 0, div = 0, livea = 0, liveb = 0; submit = 0; div = 0; livea = 0; liveb = 0;
jQuery("div#nothiddendiv").trigger("click"); jQuery("div#nothiddendiv").trigger("click");
equal( submit, 0, "undelegate Click on inner div" ); equal( submit, 0, "undelegate Click on inner div" );
equal( div, 1, "undelegate Click on inner div" ); equal( div, 1, "undelegate Click on inner div" );
...@@ -2089,7 +2099,7 @@ test(".delegate()/.undelegate()", function() { ...@@ -2089,7 +2099,7 @@ test(".delegate()/.undelegate()", function() {
equal( liveb, 0, "undelegate Click on inner div" ); equal( liveb, 0, "undelegate Click on inner div" );
// Make sure that stopPropgation doesn't stop live events // Make sure that stopPropgation doesn't stop live events
submit = 0, div = 0, livea = 0, liveb = 0; submit = 0; div = 0; livea = 0; liveb = 0;
jQuery("#body").delegate("div#nothiddendivchild", "click", function(e){ liveb++; e.stopPropagation(); }); jQuery("#body").delegate("div#nothiddendivchild", "click", function(e){ liveb++; e.stopPropagation(); });
jQuery("div#nothiddendivchild").trigger("click"); jQuery("div#nothiddendivchild").trigger("click");
equal( submit, 0, "stopPropagation Click on inner div" ); equal( submit, 0, "stopPropagation Click on inner div" );
...@@ -2098,7 +2108,7 @@ test(".delegate()/.undelegate()", function() { ...@@ -2098,7 +2108,7 @@ test(".delegate()/.undelegate()", function() {
equal( liveb, 1, "stopPropagation Click on inner div" ); equal( liveb, 1, "stopPropagation Click on inner div" );
// Make sure click events only fire with primary click // Make sure click events only fire with primary click
submit = 0, div = 0, livea = 0, liveb = 0; submit = 0; div = 0; livea = 0; liveb = 0;
var event = jQuery.Event("click"); var event = jQuery.Event("click");
event.button = 1; event.button = 1;
jQuery("div#nothiddendiv").trigger(event); jQuery("div#nothiddendiv").trigger(event);
...@@ -2143,7 +2153,7 @@ test(".delegate()/.undelegate()", function() { ...@@ -2143,7 +2153,7 @@ test(".delegate()/.undelegate()", function() {
jQuery("#body").delegate("#foo", "click", true, jQuery.proxy(function(e, data){ jQuery("#body").delegate("#foo", "click", true, jQuery.proxy(function(e, data){
equal( e.data, true, "delegate with with different this object, event data, and trigger data" ); equal( e.data, true, "delegate with with different this object, event data, and trigger data" );
equal( this.foo, "bar", "delegate with with different this object, event data, and trigger data" ); equal( this.foo, "bar", "delegate with with different this object, event data, and trigger data" );
equal( data, true, "delegate with with different this object, event data, and trigger data") equal( data, true, "delegate with with different this object, event data, and trigger data");
}, { foo: "bar" })); }, { foo: "bar" }));
jQuery("#foo").trigger("click", true); jQuery("#foo").trigger("click", true);
jQuery("#body").undelegate("#foo", "click"); jQuery("#body").undelegate("#foo", "click");
...@@ -2157,7 +2167,7 @@ test(".delegate()/.undelegate()", function() { ...@@ -2157,7 +2167,7 @@ test(".delegate()/.undelegate()", function() {
// Verify that .preventDefault() prevents default action // Verify that .preventDefault() prevents default action
jQuery("#body").delegate("#anchor2", "click", function(e){ e.preventDefault(); }); jQuery("#body").delegate("#anchor2", "click", function(e){ e.preventDefault(); });
var hash = window.location.hash; hash = window.location.hash;
jQuery("#anchor2").trigger("click"); jQuery("#anchor2").trigger("click");
equal( window.location.hash, hash, "e.preventDefault() worked" ); equal( window.location.hash, hash, "e.preventDefault() worked" );
jQuery("#body").undelegate("#anchor2", "click"); jQuery("#body").undelegate("#anchor2", "click");
...@@ -2368,7 +2378,7 @@ test("delegate with change", function(){ ...@@ -2368,7 +2378,7 @@ test("delegate with change", function(){
var checkbox = jQuery("#check2"), var checkbox = jQuery("#check2"),
checkboxFunction = function(){ checkboxFunction = function(){
checkboxChange++; checkboxChange++;
} };
jQuery("#body").delegate("#check2", "change", checkboxFunction); jQuery("#body").delegate("#check2", "change", checkboxFunction);
// test click on select // test click on select
...@@ -2556,7 +2566,7 @@ test("custom events with colons (#3533, #8272)", function() { ...@@ -2556,7 +2566,7 @@ test("custom events with colons (#3533, #8272)", function() {
ok( true, "colon events don't throw" ); ok( true, "colon events don't throw" );
} catch ( e ) { } catch ( e ) {
ok( false, "colon events die" ); ok( false, "colon events die" );
}; }
tab.remove(); tab.remove();
}); });
...@@ -2883,7 +2893,7 @@ if ( hasPHP ) { ...@@ -2883,7 +2893,7 @@ if ( hasPHP ) {
jQuery(document).ready(makeHandler("e")); jQuery(document).ready(makeHandler("e"));
jQuery(document).bind("ready.readytest", makeHandler("f")); jQuery(document).bind("ready.readytest", makeHandler("f"));
noEarlyExecution = order.length == 0; noEarlyExecution = order.length === 0;
// This assumes that QUnit tests are run on DOM ready! // This assumes that QUnit tests are run on DOM ready!
test("jQuery ready", function() { test("jQuery ready", function() {
......
...@@ -6,6 +6,7 @@ Array.prototype.arrayProtoFn = function(arg) { throw("arrayProtoFn should not be ...@@ -6,6 +6,7 @@ Array.prototype.arrayProtoFn = function(arg) { throw("arrayProtoFn should not be
var bareObj = function(value) { return value; }; var bareObj = function(value) { return value; };
var functionReturningObj = function(value) { return (function() { return value; }); }; var functionReturningObj = function(value) { return (function() { return value; }); };
/* /*
======== local reference ======= ======== local reference =======
bareObj and functionReturningObj can be used to test passing functions to setters bareObj and functionReturningObj can be used to test passing functions to setters
...@@ -155,7 +156,7 @@ var testWrap = function(val) { ...@@ -155,7 +156,7 @@ var testWrap = function(val) {
// clean up attached elements // clean up attached elements
QUnit.reset(); QUnit.reset();
} };
test("wrap(String|Element)", function() { test("wrap(String|Element)", function() {
testWrap(bareObj); testWrap(bareObj);
...@@ -205,13 +206,13 @@ var testWrapAll = function(val) { ...@@ -205,13 +206,13 @@ var testWrapAll = function(val) {
equal( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" ); equal( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
QUnit.reset(); QUnit.reset();
var prev = jQuery("#firstp")[0].previousSibling; prev = jQuery("#firstp")[0].previousSibling;
var p = jQuery("#first")[0].parentNode; p = jQuery("#first")[0].parentNode;
var result = jQuery("#firstp,#first").wrapAll(val( document.getElementById("empty") )); result = jQuery("#firstp,#first").wrapAll(val( document.getElementById("empty") ));
equal( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" ); equal( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" );
equal( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" ); equal( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
equal( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" ); equal( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" );
} };
test("wrapAll(String|Element)", function() { test("wrapAll(String|Element)", function() {
testWrapAll(bareObj); testWrapAll(bareObj);
...@@ -226,15 +227,15 @@ var testWrapInner = function(val) { ...@@ -226,15 +227,15 @@ var testWrapInner = function(val) {
equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" ); equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
QUnit.reset(); QUnit.reset();
var num = jQuery("#first").html("foo<div>test</div><div>test2</div>").children().length; num = jQuery("#first").html("foo<div>test</div><div>test2</div>").children().length;
var result = jQuery("#first").wrapInner(val("<div class='red'><div id='tmp'></div></div>")); result = jQuery("#first").wrapInner(val("<div class='red'><div id='tmp'></div></div>"));
equal( jQuery("#first").children().length, 1, "Only one child" ); equal( jQuery("#first").children().length, 1, "Only one child" );
ok( jQuery("#first").children().is(".red"), "Verify Right Element" ); ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" ); equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
QUnit.reset(); QUnit.reset();
var num = jQuery("#first").children().length; num = jQuery("#first").children().length;
var result = jQuery("#first").wrapInner(val(document.getElementById("empty"))); result = jQuery("#first").wrapInner(val(document.getElementById("empty")));
equal( jQuery("#first").children().length, 1, "Only one child" ); equal( jQuery("#first").children().length, 1, "Only one child" );
ok( jQuery("#first").children().is("#empty"), "Verify Right Element" ); ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" ); equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
...@@ -243,14 +244,14 @@ var testWrapInner = function(val) { ...@@ -243,14 +244,14 @@ var testWrapInner = function(val) {
div.wrapInner(val("<span></span>")); div.wrapInner(val("<span></span>"));
equal(div.children().length, 1, "The contents were wrapped."); equal(div.children().length, 1, "The contents were wrapped.");
equal(div.children()[0].nodeName.toLowerCase(), "span", "A span was inserted."); equal(div.children()[0].nodeName.toLowerCase(), "span", "A span was inserted.");
} };
test("wrapInner(String|Element)", function() { test("wrapInner(String|Element)", function() {
testWrapInner(bareObj); testWrapInner(bareObj);
}); });
test("wrapInner(Function)", function() { test("wrapInner(Function)", function() {
testWrapInner(functionReturningObj) testWrapInner(functionReturningObj);
}); });
test("unwrap()", function() { test("unwrap()", function() {
...@@ -347,7 +348,8 @@ var testAppendForObject = function(valueObj, isFragment) { ...@@ -347,7 +348,8 @@ var testAppendForObject = function(valueObj, isFragment) {
equal( obj.children("form").size(), 1, "Check for appending a form" + objType ); // Bug #910 equal( obj.children("form").size(), 1, "Check for appending a form" + objType ); // Bug #910
QUnit.reset(); QUnit.reset();
var obj = getObj(); obj = getObj();
var prev = obj.children().length; var prev = obj.children().length;
obj.append( obj.append(
...@@ -358,14 +360,14 @@ var testAppendForObject = function(valueObj, isFragment) { ...@@ -358,14 +360,14 @@ var testAppendForObject = function(valueObj, isFragment) {
equal( obj.children().length, prev + 3, "Make sure that multiple arguments works." + objType ); equal( obj.children().length, prev + 3, "Make sure that multiple arguments works." + objType );
QUnit.reset(); QUnit.reset();
} };
var testAppend = function(valueObj) { var testAppend = function(valueObj) {
expect(58); expect(58);
testAppendForObject(valueObj, false); testAppendForObject(valueObj, false);
testAppendForObject(valueObj, true); testAppendForObject(valueObj, true);
var defaultText = "Try them out:" var defaultText = "Try them out:";
var result = jQuery("#first").append(valueObj("<b>buga</b>")); var result = jQuery("#first").append(valueObj("<b>buga</b>"));
equal( result.text(), defaultText + "buga", "Check if text appending works" ); equal( result.text(), defaultText + "buga", "Check if text appending works" );
equal( jQuery("#select3").append(valueObj("<option value='appendTest'>Append Test</option>")).find("option:last-child").attr("value"), "appendTest", "Appending html options to select element"); equal( jQuery("#select3").append(valueObj("<option value='appendTest'>Append Test</option>")).find("option:last-child").attr("value"), "appendTest", "Appending html options to select element");
...@@ -455,7 +457,7 @@ var testAppend = function(valueObj) { ...@@ -455,7 +457,7 @@ var testAppend = function(valueObj) {
equal( $radio[0].checked, true, "Reappending radios uphold which radio is checked" ); equal( $radio[0].checked, true, "Reappending radios uphold which radio is checked" );
equal( $radioNot[0].checked, false, "Reappending radios uphold not being checked" ); equal( $radioNot[0].checked, false, "Reappending radios uphold not being checked" );
QUnit.reset(); QUnit.reset();
} };
test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() { test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() {
testAppend(bareObj); testAppend(bareObj);
...@@ -574,7 +576,7 @@ test("append HTML5 sectioning elements (Bug #6485)", function () { ...@@ -574,7 +576,7 @@ test("append HTML5 sectioning elements (Bug #6485)", function () {
aside = jQuery("aside"); aside = jQuery("aside");
equal( article.get( 0 ).style.fontSize, "10px", "HTML5 elements are styleable"); equal( article.get( 0 ).style.fontSize, "10px", "HTML5 elements are styleable");
equal( aside.length, 1, "HTML5 elements do not collapse their children") equal( aside.length, 1, "HTML5 elements do not collapse their children");
}); });
if ( jQuery.css ) { if ( jQuery.css ) {
...@@ -652,7 +654,7 @@ test("append(xml)", function() { ...@@ -652,7 +654,7 @@ test("append(xml)", function() {
try { try {
elem = new ActiveXObject( aActiveX[ n ] ); elem = new ActiveXObject( aActiveX[ n ] );
return elem; return elem;
} catch(_){}; } catch(_){}
} }
} }
} }
...@@ -668,7 +670,8 @@ test("append(xml)", function() { ...@@ -668,7 +670,8 @@ test("append(xml)", function() {
test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() { test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
expect( 16 + ( jQuery.getScript ? 1 : 0 ) ); expect( 16 + ( jQuery.getScript ? 1 : 0 ) );
var defaultText = "Try them out:" var defaultText = "Try them out:";
jQuery("<b>buga</b>").appendTo("#first"); jQuery("<b>buga</b>").appendTo("#first");
equal( jQuery("#first").text(), defaultText + "buga", "Check if text appending works" ); equal( jQuery("#first").text(), defaultText + "buga", "Check if text appending works" );
equal( jQuery("<option value='appendTest'>Append Test</option>").appendTo("#select3").parent().find("option:last-child").attr("value"), "appendTest", "Appending html options to select element"); equal( jQuery("<option value='appendTest'>Append Test</option>").appendTo("#select3").parent().find("option:last-child").attr("value"), "appendTest", "Appending html options to select element");
...@@ -750,8 +753,9 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() { ...@@ -750,8 +753,9 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
var testPrepend = function(val) { var testPrepend = function(val) {
expect(6); expect(6);
var defaultText = "Try them out:" var defaultText = "Try them out:",
var result = jQuery("#first").prepend(val( "<b>buga</b>" )); result = jQuery("#first").prepend(val( "<b>buga</b>" ));
equal( result.text(), "buga" + defaultText, "Check if text prepending works" ); equal( result.text(), "buga" + defaultText, "Check if text prepending works" );
equal( jQuery("#select3").prepend(val( "<option value='prependTest'>Prepend Test</option>" )).find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element"); equal( jQuery("#select3").prepend(val( "<option value='prependTest'>Prepend Test</option>" )).find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element");
...@@ -837,7 +841,7 @@ test("prepend(Function) with incoming value", function() { ...@@ -837,7 +841,7 @@ test("prepend(Function) with incoming value", function() {
test("prependTo(String|Element|Array&lt;Element&gt;|jQuery)", function() { test("prependTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
expect(6); expect(6);
var defaultText = "Try them out:" var defaultText = "Try them out:";
jQuery("<b>buga</b>").prependTo("#first"); jQuery("<b>buga</b>").prependTo("#first");
equal( jQuery("#first").text(), "buga" + defaultText, "Check if text prepending works" ); equal( jQuery("#first").text(), "buga" + defaultText, "Check if text prepending works" );
equal( jQuery("<option value='prependTest'>Prepend Test</option>").prependTo("#select3").parent().find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element"); equal( jQuery("<option value='prependTest'>Prepend Test</option>").prependTo("#select3").parent().find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element");
...@@ -893,7 +897,7 @@ var testBefore = function(val) { ...@@ -893,7 +897,7 @@ var testBefore = function(val) {
var set = jQuery("<div/>").before("<span>test</span>"); var set = jQuery("<div/>").before("<span>test</span>");
equal( set[0].nodeName.toLowerCase(), "span", "Insert the element before the disconnected node." ); equal( set[0].nodeName.toLowerCase(), "span", "Insert the element before the disconnected node." );
equal( set.length, 2, "Insert the element before the disconnected node." ); equal( set.length, 2, "Insert the element before the disconnected node." );
} };
test("before(String|Element|Array&lt;Element&gt;|jQuery)", function() { test("before(String|Element|Array&lt;Element&gt;|jQuery)", function() {
testBefore(bareObj); testBefore(bareObj);
...@@ -901,7 +905,7 @@ test("before(String|Element|Array&lt;Element&gt;|jQuery)", function() { ...@@ -901,7 +905,7 @@ test("before(String|Element|Array&lt;Element&gt;|jQuery)", function() {
test("before(Function)", function() { test("before(Function)", function() {
testBefore(functionReturningObj); testBefore(functionReturningObj);
}) });
test("before and after w/ empty object (#10812)", function() { test("before and after w/ empty object (#10812)", function() {
expect(2); expect(2);
...@@ -970,7 +974,7 @@ test("after(String|Element|Array&lt;Element&gt;|jQuery)", function() { ...@@ -970,7 +974,7 @@ test("after(String|Element|Array&lt;Element&gt;|jQuery)", function() {
test("after(Function)", function() { test("after(Function)", function() {
testAfter(functionReturningObj); testAfter(functionReturningObj);
}) });
test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() { test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() {
expect(4); expect(4);
...@@ -1080,7 +1084,7 @@ var testReplaceWith = function(val) { ...@@ -1080,7 +1084,7 @@ var testReplaceWith = function(val) {
jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") ); jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") );
equal( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); equal( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
} };
test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() { test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() {
testReplaceWith(bareObj); testReplaceWith(bareObj);
...@@ -1266,7 +1270,8 @@ test("clone()", function() { ...@@ -1266,7 +1270,8 @@ test("clone()", function() {
var form = document.createElement("form"); var form = document.createElement("form");
form.action = "/test/"; form.action = "/test/";
var div = document.createElement("div");
div = document.createElement("div");
div.appendChild( document.createTextNode("test") ); div.appendChild( document.createTextNode("test") );
form.appendChild( div ); form.appendChild( div );
...@@ -1286,7 +1291,8 @@ test("clone(script type=non-javascript) (#11359)", function() { ...@@ -1286,7 +1291,8 @@ test("clone(script type=non-javascript) (#11359)", function() {
test("clone(form element) (Bug #3879, #6655)", function() { test("clone(form element) (Bug #3879, #6655)", function() {
expect(5); expect(5);
var element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>"); var clone,
element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>");
equal( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" ); equal( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" );
...@@ -1352,7 +1358,9 @@ var testHtml = function(valueObj) { ...@@ -1352,7 +1358,9 @@ var testHtml = function(valueObj) {
div.html(valueObj("<b>test</b>")); div.html(valueObj("<b>test</b>"));
var pass = true; var pass = true;
for ( var i = 0; i < div.size(); i++ ) { for ( var i = 0; i < div.size(); i++ ) {
if ( div.get(i).childNodes.length != 1 ) pass = false; if ( div.get(i).childNodes.length != 1 ) {
pass = false;
}
} }
ok( pass, "Set HTML" ); ok( pass, "Set HTML" );
...@@ -1416,7 +1424,7 @@ var testHtml = function(valueObj) { ...@@ -1416,7 +1424,7 @@ var testHtml = function(valueObj) {
jQuery("#qunit-fixture").html(valueObj("foo <form><script type='text/javascript'>ok( true, 'jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975 (2)' );</script></form>")); jQuery("#qunit-fixture").html(valueObj("foo <form><script type='text/javascript'>ok( true, 'jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975 (2)' );</script></form>"));
jQuery("#qunit-fixture").html(valueObj("<script>equal(jQuery.scriptorder++, 0, 'Script is executed in order');equal(jQuery('#scriptorder').length, 1,'Execute after html (even though appears before)')<\/script><span id='scriptorder'><script>equal(jQuery.scriptorder++, 1, 'Script (nested) is executed in order');equal(jQuery('#scriptorder').length, 1,'Execute after html')<\/script></span><script>equal(jQuery.scriptorder++, 2, 'Script (unnested) is executed in order');equal(jQuery('#scriptorder').length, 1,'Execute after html')<\/script>")); jQuery("#qunit-fixture").html(valueObj("<script>equal(jQuery.scriptorder++, 0, 'Script is executed in order');equal(jQuery('#scriptorder').length, 1,'Execute after html (even though appears before)')<\/script><span id='scriptorder'><script>equal(jQuery.scriptorder++, 1, 'Script (nested) is executed in order');equal(jQuery('#scriptorder').length, 1,'Execute after html')<\/script></span><script>equal(jQuery.scriptorder++, 2, 'Script (unnested) is executed in order');equal(jQuery('#scriptorder').length, 1,'Execute after html')<\/script>"));
} };
test("html(String)", function() { test("html(String)", function() {
testHtml(bareObj); testHtml(bareObj);
...@@ -1440,7 +1448,7 @@ test("html(Function)", function() { ...@@ -1440,7 +1448,7 @@ test("html(Function)", function() {
test("html(Function) with incoming value", function() { test("html(Function) with incoming value", function() {
expect(20); expect(20);
var div = jQuery("#qunit-fixture > div"), old = div.map(function(){ return jQuery(this).html() }); var div = jQuery("#qunit-fixture > div"), old = div.map(function(){ return jQuery(this).html(); });
div.html(function(i, val) { div.html(function(i, val) {
equal( val, old[i], "Make sure the incoming value is correct." ); equal( val, old[i], "Make sure the incoming value is correct." );
...@@ -1452,7 +1460,7 @@ test("html(Function) with incoming value", function() { ...@@ -1452,7 +1460,7 @@ test("html(Function) with incoming value", function() {
if ( this.childNodes.length !== 1 ) { if ( this.childNodes.length !== 1 ) {
pass = false; pass = false;
} }
}) });
ok( pass, "Set HTML" ); ok( pass, "Set HTML" );
QUnit.reset(); QUnit.reset();
...@@ -1505,7 +1513,9 @@ test("html(Function) with incoming value", function() { ...@@ -1505,7 +1513,9 @@ test("html(Function) with incoming value", function() {
var testRemove = function(method) { var testRemove = function(method) {
expect(9); expect(9);
var first = jQuery("#ap").children(":first"); var cleanUp, count,
first = jQuery("#ap").children(":first");
first.data("foo", "bar"); first.data("foo", "bar");
jQuery("#ap").children()[method](); jQuery("#ap").children()[method]();
...@@ -1535,9 +1545,11 @@ var testRemove = function(method) { ...@@ -1535,9 +1545,11 @@ var testRemove = function(method) {
QUnit.reset(); QUnit.reset();
var count = 0; count = 0;
var first = jQuery("#ap").children(":first");
var cleanUp = first.click(function() { count++ })[method]().appendTo("#qunit-fixture").click(); first = jQuery("#ap").children(":first");
cleanUp = first.click(function() { count++; })[method]().appendTo("#qunit-fixture").click();
equal( method == "remove" ? 0 : 1, count ); equal( method == "remove" ? 0 : 1, count );
......
...@@ -86,8 +86,8 @@ testIframe("offset/absolute", "absolute", function( jQuery ) { ...@@ -86,8 +86,8 @@ testIframe("offset/absolute", "absolute", function( jQuery ) {
// test #5781 // test #5781
var offset = jQuery( "#positionTest" ).offset({ top: 10, left: 10 }).offset(); 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.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.left, 10, "Setting offset on element with position absolute but 'auto' values." );
// set offset // set offset
......
...@@ -60,7 +60,7 @@ test("queue(name) passes in the next item in the queue as a parameter", function ...@@ -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"); equal(++counter, 2, "Next was called");
next(); next();
}).queue("bar", function() { }).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"); div.dequeue("foo");
...@@ -76,12 +76,12 @@ test("queue() passes in the next item in the queue as a parameter to fx queues", ...@@ -76,12 +76,12 @@ test("queue() passes in the next item in the queue as a parameter to fx queues",
div.queue(function(next) { div.queue(function(next) {
equal(++counter, 1, "Dequeueing"); equal(++counter, 1, "Dequeueing");
var self = this; var self = this;
setTimeout(function() { next() }, 500); setTimeout(function() { next(); }, 500);
}).queue(function(next) { }).queue(function(next) {
equal(++counter, 2, "Next was called"); equal(++counter, 2, "Next was called");
next(); next();
}).queue("bar", function() { }).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() { jQuery.when( div.promise("fx"), div ).done(function() {
...@@ -136,7 +136,7 @@ test("delay()", function() { ...@@ -136,7 +136,7 @@ test("delay()", function() {
test("clearQueue(name) clears the queue", function() { test("clearQueue(name) clears the queue", function() {
expect(2); expect(2);
stop() stop();
var div = jQuery({}); var div = jQuery({});
var counter = 0; var counter = 0;
......
...@@ -12,8 +12,8 @@ test("element - jQuery only", function() { ...@@ -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("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." ); 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("#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("#lengthtest input").length, "<input name=\"length\"> cannot be found under IE, see #945" );
//#7533 //#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" ); 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 ...@@ -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() { ...@@ -202,9 +202,11 @@ test("filter(Selector|undefined)", function() {
test("filter(Function)", function() { test("filter(Function)", function() {
expect(2); 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() { test("filter(Element)", function() {
...@@ -341,7 +343,7 @@ test("not(Element)", function() { ...@@ -341,7 +343,7 @@ test("not(Element)", function() {
}); });
test("not(Function)", 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() { test("not(Array)", function() {
...@@ -600,15 +602,15 @@ test("add(String|Element|Array|undefined)", function() { ...@@ -600,15 +602,15 @@ test("add(String|Element|Array|undefined)", function() {
equal( x[0].id, "x1", "Check on-the-fly element1" ); equal( x[0].id, "x1", "Check on-the-fly element1" );
equal( x[1].id, "x2", "Check on-the-fly element2" ); 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[0].id, "x1", "Check on-the-fly element1" );
equal( x[1].id, "x2", "Check on-the-fly element2" ); 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[0].id, "x1", "Check on-the-fly element1" );
equal( x[1].id, "x2", "Check on-the-fly element2" ); 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[0].id, "x1", "Check on-the-fly element1" );
equal( x[1].id, "x2", "Check on-the-fly element2" ); equal( x[1].id, "x2", "Check on-the-fly element2" );
...@@ -640,4 +642,3 @@ test("eq('-1') #10616", function() { ...@@ -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" ); 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" ); 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