Commit f35ba5e6 authored by Mike Sherov's avatar Mike Sherov Committed by Dave Methvin

Fix #10691. Remove all instances of equals() and same(), as these are deprecated in QUnit.

parent 83c72eaa
...@@ -41,7 +41,7 @@ function t(a,b,c) { ...@@ -41,7 +41,7 @@ function t(a,b,c) {
s += (s && ",") + '"' + f[i].id + '"'; s += (s && ",") + '"' + f[i].id + '"';
} }
same(f, q.apply(q,c), a + " (" + b + ")"); deepEqual(f, q.apply(q,c), a + " (" + b + ")");
} }
var fireNative; var fireNative;
...@@ -102,19 +102,19 @@ function url(value) { ...@@ -102,19 +102,19 @@ function url(value) {
// Because QUnit doesn't have a mechanism for retrieving the number of expected assertions for a test, // Because QUnit doesn't have a mechanism for retrieving the number of expected assertions for a test,
// if we unconditionally assert any of these, the test will fail with too many assertions :| // if we unconditionally assert any of these, the test will fail with too many assertions :|
if ( cacheLength !== oldCacheLength ) { if ( cacheLength !== oldCacheLength ) {
equals( cacheLength, oldCacheLength, "No unit tests leak memory in jQuery.cache" ); equal( cacheLength, oldCacheLength, "No unit tests leak memory in jQuery.cache" );
oldCacheLength = cacheLength; oldCacheLength = cacheLength;
} }
if ( fragmentsLength !== oldFragmentsLength ) { if ( fragmentsLength !== oldFragmentsLength ) {
equals( fragmentsLength, oldFragmentsLength, "No unit tests leak memory in jQuery.fragments" ); equal( fragmentsLength, oldFragmentsLength, "No unit tests leak memory in jQuery.fragments" );
oldFragmentsLength = fragmentsLength; oldFragmentsLength = fragmentsLength;
} }
if ( jQuery.timers.length !== oldTimersLength ) { if ( jQuery.timers.length !== oldTimersLength ) {
equals( jQuery.timers.length, oldTimersLength, "No timers are still running" ); equal( jQuery.timers.length, oldTimersLength, "No timers are still running" );
oldTimersLength = jQuery.timers.length; oldTimersLength = jQuery.timers.length;
} }
if ( jQuery.active !== oldActive ) { if ( jQuery.active !== oldActive ) {
equals( jQuery.active, 0, "No AJAX requests are still active" ); equal( jQuery.active, 0, "No AJAX requests are still active" );
oldActive = jQuery.active; oldActive = jQuery.active;
} }
} }
......
...@@ -25,9 +25,3 @@ jQuery.noConflict(); // Allow the test to run with other libs or jQuery's. ...@@ -25,9 +25,3 @@ jQuery.noConflict(); // Allow the test to run with other libs or jQuery's.
document.write("<scr" + "ipt src='http://swarm.jquery.org/js/inject.js?" + (new Date).getTime() + "'></scr" + "ipt>"); document.write("<scr" + "ipt src='http://swarm.jquery.org/js/inject.js?" + (new Date).getTime() + "'></scr" + "ipt>");
})(); })();
// QUnit Aliases
(function() {
window.equals = window.equal;
window.same = window.deepEqual;
})();
...@@ -474,7 +474,7 @@ test(".ajax() - protocol-less urls", function() { ...@@ -474,7 +474,7 @@ test(".ajax() - protocol-less urls", function() {
jQuery.ajax({ jQuery.ajax({
url: "//somedomain.com", url: "//somedomain.com",
beforeSend: function( xhr, settings ) { beforeSend: function( xhr, settings ) {
equals(settings.url, location.protocol + "//somedomain.com", "Make sure that the protocol is added."); equal(settings.url, location.protocol + "//somedomain.com", "Make sure that the protocol is added.");
return false; return false;
} }
}); });
...@@ -486,7 +486,7 @@ test(".ajax() - hash", function() { ...@@ -486,7 +486,7 @@ test(".ajax() - hash", function() {
jQuery.ajax({ jQuery.ajax({
url: "data/name.html#foo", url: "data/name.html#foo",
beforeSend: function( xhr, settings ) { beforeSend: function( xhr, settings ) {
equals(settings.url, "data/name.html", "Make sure that the URL is trimmed."); equal(settings.url, "data/name.html", "Make sure that the URL is trimmed.");
return false; return false;
} }
}); });
...@@ -494,7 +494,7 @@ test(".ajax() - hash", function() { ...@@ -494,7 +494,7 @@ test(".ajax() - hash", function() {
jQuery.ajax({ jQuery.ajax({
url: "data/name.html?abc#foo", url: "data/name.html?abc#foo",
beforeSend: function( xhr, settings ) { beforeSend: function( xhr, settings ) {
equals(settings.url, "data/name.html?abc", "Make sure that the URL is trimmed."); equal(settings.url, "data/name.html?abc", "Make sure that the URL is trimmed.");
return false; return false;
} }
}); });
...@@ -503,7 +503,7 @@ test(".ajax() - hash", function() { ...@@ -503,7 +503,7 @@ test(".ajax() - hash", function() {
url: "data/name.html?abc#foo", url: "data/name.html?abc#foo",
data: { "test": 123 }, data: { "test": 123 },
beforeSend: function( xhr, settings ) { beforeSend: function( xhr, settings ) {
equals(settings.url, "data/name.html?abc&test=123", "Make sure that the URL is trimmed."); equal(settings.url, "data/name.html?abc&test=123", "Make sure that the URL is trimmed.");
return false; return false;
} }
}); });
...@@ -619,10 +619,10 @@ test("jQuery.ajax() - abort", function() { ...@@ -619,10 +619,10 @@ test("jQuery.ajax() - abort", function() {
complete: function(){ ok(true, "complete"); } complete: function(){ ok(true, "complete"); }
}); });
equals( xhr.readyState, 1, "XHR readyState indicates successful dispatch" ); equal( xhr.readyState, 1, "XHR readyState indicates successful dispatch" );
xhr.abort(); xhr.abort();
equals( xhr.readyState, 0, "XHR readyState indicates successful abortion" ); equal( xhr.readyState, 0, "XHR readyState indicates successful abortion" );
}); });
test("Ajax events with context", function() { test("Ajax events with context", function() {
...@@ -632,18 +632,18 @@ test("Ajax events with context", function() { ...@@ -632,18 +632,18 @@ test("Ajax events with context", function() {
var context = document.createElement("div"); var context = document.createElement("div");
function event(e){ function event(e){
equals( this, context, e.type ); equal( this, context, e.type );
} }
function callback(msg){ function callback(msg){
return function(){ return function(){
equals( this, context, "context is preserved on callback " + msg ); equal( this, context, "context is preserved on callback " + msg );
}; };
} }
function nocallback(msg){ function nocallback(msg){
return function(){ return function(){
equals( typeof this.url, "string", "context is settings on callback " + msg ); equal( typeof this.url, "string", "context is settings on callback " + msg );
}; };
} }
...@@ -705,7 +705,7 @@ test("jQuery.ajax context modification", function() { ...@@ -705,7 +705,7 @@ test("jQuery.ajax context modification", function() {
} }
}); });
equals( obj.test, "foo", "Make sure the original object is maintained." ); equal( obj.test, "foo", "Make sure the original object is maintained." );
}); });
test("jQuery.ajax context modification through ajaxSetup", function() { test("jQuery.ajax context modification through ajaxSetup", function() {
...@@ -787,9 +787,9 @@ test("jQuery.ajax - xml: non-namespace elements inside namespaced elements", fun ...@@ -787,9 +787,9 @@ test("jQuery.ajax - xml: non-namespace elements inside namespaced elements", fun
url: url("data/with_fries.xml"), url: url("data/with_fries.xml"),
dataType: "xml", dataType: "xml",
success: function(resp) { success: function(resp) {
equals( jQuery("properties", resp).length, 1, "properties in responseXML" ); equal( jQuery("properties", resp).length, 1, "properties in responseXML" );
equals( jQuery("jsconf", resp).length, 1, "jsconf in responseXML" ); equal( jQuery("jsconf", resp).length, 1, "jsconf in responseXML" );
equals( jQuery("thing", resp).length, 2, "things in responseXML" ); equal( jQuery("thing", resp).length, 2, "things in responseXML" );
start(); start();
} }
}); });
...@@ -802,9 +802,9 @@ test("jQuery.ajax - xml: non-namespace elements inside namespaced elements (over ...@@ -802,9 +802,9 @@ test("jQuery.ajax - xml: non-namespace elements inside namespaced elements (over
url: url("data/with_fries_over_jsonp.php"), url: url("data/with_fries_over_jsonp.php"),
dataType: "jsonp xml", dataType: "jsonp xml",
success: function(resp) { success: function(resp) {
equals( jQuery("properties", resp).length, 1, "properties in responseXML" ); equal( jQuery("properties", resp).length, 1, "properties in responseXML" );
equals( jQuery("jsconf", resp).length, 1, "jsconf in responseXML" ); equal( jQuery("jsconf", resp).length, 1, "jsconf in responseXML" );
equals( jQuery("thing", resp).length, 2, "things in responseXML" ); equal( jQuery("thing", resp).length, 2, "things in responseXML" );
start(); start();
}, },
error: function(_1,_2,error) { error: function(_1,_2,error) {
...@@ -910,8 +910,8 @@ test("jQuery.ajax - dataType html", function() { ...@@ -910,8 +910,8 @@ test("jQuery.ajax - dataType html", function() {
stop(); stop();
var verifyEvaluation = function() { var verifyEvaluation = function() {
equals( testFoo, "foo", "Check if script was evaluated for datatype html" ); equal( testFoo, "foo", "Check if script was evaluated for datatype html" );
equals( foobar, "bar", "Check if script src was evaluated for datatype html" ); equal( foobar, "bar", "Check if script src was evaluated for datatype html" );
start(); start();
}; };
...@@ -936,28 +936,28 @@ test("serialize()", function() { ...@@ -936,28 +936,28 @@ test("serialize()", function() {
"<input type='number' id='html5number' name='number' value='43' />" "<input type='number' id='html5number' name='number' value='43' />"
); );
equals( jQuery("#form").serialize(), equal( jQuery("#form").serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3", "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
"Check form serialization as query string"); "Check form serialization as query string");
equals( jQuery("#form :input").serialize(), equal( jQuery("#form :input").serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3", "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
"Check input serialization as query string"); "Check input serialization as query string");
equals( jQuery("#testForm").serialize(), equal( jQuery("#testForm").serialize(),
"T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", "T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
"Check form serialization as query string"); "Check form serialization as query string");
equals( jQuery("#testForm :input").serialize(), equal( jQuery("#testForm :input").serialize(),
"T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", "T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
"Check input serialization as query string"); "Check input serialization as query string");
equals( jQuery("#form, #testForm").serialize(), equal( jQuery("#form, #testForm").serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
"Multiple form serialization as query string"); "Multiple form serialization as query string");
/* Temporarily disabled. Opera 10 has problems with form serialization. /* Temporarily disabled. Opera 10 has problems with form serialization.
equals( jQuery("#form, #testForm :input").serialize(), equal( jQuery("#form, #testForm :input").serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
"Mixed form/input serialization as query string"); "Mixed form/input serialization as query string");
*/ */
...@@ -967,68 +967,68 @@ test("serialize()", function() { ...@@ -967,68 +967,68 @@ test("serialize()", function() {
test("jQuery.param()", function() { test("jQuery.param()", function() {
expect(21); expect(21);
equals( !jQuery.ajaxSettings.traditional, true, "traditional flag, falsy by default" ); equal( !jQuery.ajaxSettings.traditional, true, "traditional flag, falsy by default" );
var params = {foo:"bar", baz:42, quux:"All your base are belong to us"}; var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
equals( 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" };
equals( jQuery.param(params), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3&regularThing=blah", "with array" ); equal( jQuery.param(params), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3&regularThing=blah", "with array" );
params = {foo: ["a", "b", "c"]}; params = {foo: ["a", "b", "c"]};
equals( jQuery.param(params), "foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c", "with array of strings" ); equal( jQuery.param(params), "foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c", "with array of strings" );
params = {foo: ["baz", 42, "All your base are belong to us"] }; params = {foo: ["baz", 42, "All your base are belong to us"] };
equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" ); equal( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
params = {foo: { bar: "baz", beep: 42, quux: "All your base are belong to us" } }; params = {foo: { bar: "baz", beep: 42, quux: "All your base are belong to us" } };
equals( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" ); equal( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" }; params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
equals( decodeURIComponent( jQuery.param(params) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=undefined&i[]=10&i[]=11&j=true&k=false&l[]=undefined&l[]=0&m=cowboy+hat?", "huge structure" ); equal( decodeURIComponent( jQuery.param(params) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=undefined&i[]=10&i[]=11&j=true&k=false&l[]=undefined&l[]=0&m=cowboy+hat?", "huge structure" );
params = { a: [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { b: [ 7, [ 8, 9 ], [ { c: 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { e: { f: { g: [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] }; params = { a: [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { b: [ 7, [ 8, 9 ], [ { c: 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { e: { f: { g: [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] };
equals( decodeURIComponent( jQuery.param(params) ), "a[]=0&a[1][]=1&a[1][]=2&a[2][]=3&a[2][1][]=4&a[2][1][]=5&a[2][2][]=6&a[3][b][]=7&a[3][b][1][]=8&a[3][b][1][]=9&a[3][b][2][0][c]=10&a[3][b][2][0][d]=11&a[3][b][3][0][]=12&a[3][b][4][0][0][]=13&a[3][b][5][e][f][g][]=14&a[3][b][5][e][f][g][1][]=15&a[3][b][]=16&a[]=17", "nested arrays" ); equal( decodeURIComponent( jQuery.param(params) ), "a[]=0&a[1][]=1&a[1][]=2&a[2][]=3&a[2][1][]=4&a[2][1][]=5&a[2][2][]=6&a[3][b][]=7&a[3][b][1][]=8&a[3][b][1][]=9&a[3][b][2][0][c]=10&a[3][b][2][0][d]=11&a[3][b][3][0][]=12&a[3][b][4][0][0][]=13&a[3][b][5][e][f][g][]=14&a[3][b][5][e][f][g][1][]=15&a[3][b][]=16&a[]=17", "nested arrays" );
params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" }; params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
equals( jQuery.param(params,true), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=undefined&l=0&m=cowboy+hat%3F", "huge structure, forced traditional" ); equal( jQuery.param(params,true), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=undefined&l=0&m=cowboy+hat%3F", "huge structure, forced traditional" );
equals( decodeURIComponent( jQuery.param({ a: [1,2,3], "b[]": [4,5,6], "c[d]": [7,8,9], e: { f: [10], g: [11,12], h: 13 } }) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." ); equal( decodeURIComponent( jQuery.param({ a: [1,2,3], "b[]": [4,5,6], "c[d]": [7,8,9], e: { f: [10], g: [11,12], h: 13 } }) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." );
// #7945 // #7945
equals( jQuery.param({"jquery": "1.4.2"}), "jquery=1.4.2", "Check that object with a jQuery property get serialized correctly" ); equal( jQuery.param({"jquery": "1.4.2"}), "jquery=1.4.2", "Check that object with a jQuery property get serialized correctly" );
jQuery.ajaxSetup({ traditional: true }); jQuery.ajaxSetup({ traditional: true });
var params = {foo:"bar", baz:42, quux:"All your base are belong to us"}; var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
equals( 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" };
equals( jQuery.param(params), "someName=1&someName=2&someName=3&regularThing=blah", "with array" ); equal( jQuery.param(params), "someName=1&someName=2&someName=3&regularThing=blah", "with array" );
params = {foo: ["a", "b", "c"]}; params = {foo: ["a", "b", "c"]};
equals( jQuery.param(params), "foo=a&foo=b&foo=c", "with array of strings" ); equal( jQuery.param(params), "foo=a&foo=b&foo=c", "with array of strings" );
params = {"foo[]":["baz", 42, "All your base are belong to us"]}; params = {"foo[]":["baz", 42, "All your base are belong to us"]};
equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" ); equal( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"}; params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"};
equals( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" ); equal( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" }; params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
equals( jQuery.param(params), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=undefined&l=0&m=cowboy+hat%3F", "huge structure" ); equal( jQuery.param(params), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=undefined&l=0&m=cowboy+hat%3F", "huge structure" );
params = { a: [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { b: [ 7, [ 8, 9 ], [ { c: 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { e: { f: { g: [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] }; params = { a: [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { b: [ 7, [ 8, 9 ], [ { c: 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { e: { f: { g: [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] };
equals( jQuery.param(params), "a=0&a=1%2C2&a=3%2C4%2C5%2C6&a=%5Bobject+Object%5D&a=17", "nested arrays (not possible when jQuery.param.traditional == true)" ); equal( jQuery.param(params), "a=0&a=1%2C2&a=3%2C4%2C5%2C6&a=%5Bobject+Object%5D&a=17", "nested arrays (not possible when jQuery.param.traditional == true)" );
params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" }; params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
equals( decodeURIComponent( jQuery.param(params,false) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=undefined&i[]=10&i[]=11&j=true&k=false&l[]=undefined&l[]=0&m=cowboy+hat?", "huge structure, forced not traditional" ); equal( decodeURIComponent( jQuery.param(params,false) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=undefined&i[]=10&i[]=11&j=true&k=false&l[]=undefined&l[]=0&m=cowboy+hat?", "huge structure, forced not traditional" );
params = { param1: null }; params = { param1: null };
equals( jQuery.param(params,false), "param1=null", "Make sure that null params aren't traversed." ); equal( jQuery.param(params,false), "param1=null", "Make sure that null params aren't traversed." );
params = {"test": {"length": 3, "foo": "bar"} }; params = {"test": {"length": 3, "foo": "bar"} };
equals( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" ); equal( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" );
}); });
test("synchronous request", function() { test("synchronous request", function() {
...@@ -1059,8 +1059,8 @@ test("pass-through request object", function() { ...@@ -1059,8 +1059,8 @@ test("pass-through request object", function() {
errorEx += ": " + xml.status; errorEx += ": " + xml.status;
}); });
jQuery("#foo").one("ajaxStop", function () { jQuery("#foo").one("ajaxStop", function () {
equals(successCount, 5, "Check all ajax calls successful"); equal(successCount, 5, "Check all ajax calls successful");
equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")"); equal(errorCount, 0, "Check no ajax errors (status" + errorEx + ")");
jQuery("#foo").unbind("ajaxError"); jQuery("#foo").unbind("ajaxError");
start(); start();
...@@ -1090,7 +1090,7 @@ test("ajax cache", function () { ...@@ -1090,7 +1090,7 @@ test("ajax cache", function () {
} }
oldOne = ret[1]; oldOne = ret[1];
} }
equals(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();
...@@ -1143,7 +1143,7 @@ test("load('url selector')", function() { ...@@ -1143,7 +1143,7 @@ test("load('url selector')", function() {
expect(1); expect(1);
stop(); // check if load can be called with only url stop(); // check if load can be called with only url
jQuery("#first").load("data/test3.html div.user", function(){ jQuery("#first").load("data/test3.html div.user", function(){
equals( jQuery(this).children("div").length, 2, "Verify that specific elements were injected" ); equal( jQuery(this).children("div").length, 2, "Verify that specific elements were injected" );
start(); start();
}); });
}); });
...@@ -1153,7 +1153,7 @@ test("load(String, Function) with ajaxSetup on dataType json, see #2046", functi ...@@ -1153,7 +1153,7 @@ test("load(String, Function) with ajaxSetup on dataType json, see #2046", functi
stop(); stop();
jQuery.ajaxSetup({ dataType: "json" }); jQuery.ajaxSetup({ dataType: "json" });
jQuery("#first").ajaxComplete(function (e, xml, s) { jQuery("#first").ajaxComplete(function (e, xml, s) {
equals( s.dataType, "html", "Verify the load() dataType was html" ); equal( s.dataType, "html", "Verify the load() dataType was html" );
jQuery("#first").unbind("ajaxComplete"); jQuery("#first").unbind("ajaxComplete");
jQuery.ajaxSetup({ dataType: "" }); jQuery.ajaxSetup({ dataType: "" });
start(); start();
...@@ -1175,15 +1175,15 @@ test("load(String, Function) - check scripts", function() { ...@@ -1175,15 +1175,15 @@ test("load(String, Function) - check scripts", function() {
stop(); stop();
var verifyEvaluation = function() { var verifyEvaluation = function() {
equals( foobar, "bar", "Check if script src was evaluated after load" ); equal( foobar, "bar", "Check if script src was evaluated after load" );
equals( jQuery("#ap").html(), "bar", "Check if script evaluation has modified DOM"); equal( jQuery("#ap").html(), "bar", "Check if script evaluation has modified DOM");
start(); start();
}; };
jQuery("#first").load(url("data/test.html"), function() { jQuery("#first").load(url("data/test.html"), function() {
ok( jQuery("#first").html().match(/^html text/), "Check content after loading html" ); ok( jQuery("#first").html().match(/^html text/), "Check content after loading html" );
equals( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM"); equal( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM");
equals( testFoo, "foo", "Check if script was evaluated after load" ); equal( testFoo, "foo", "Check if script was evaluated after load" );
setTimeout(verifyEvaluation, 600); setTimeout(verifyEvaluation, 600);
}); });
}); });
...@@ -1193,8 +1193,8 @@ test("load(String, Function) - check file with only a script tag", function() { ...@@ -1193,8 +1193,8 @@ test("load(String, Function) - check file with only a script tag", function() {
stop(); stop();
jQuery("#first").load(url("data/test2.html"), function() { jQuery("#first").load(url("data/test2.html"), function() {
equals( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM"); equal( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM");
equals( testFoo, "foo", "Check if script was evaluated after load" ); equal( testFoo, "foo", "Check if script was evaluated after load" );
start(); start();
}); });
...@@ -1218,8 +1218,8 @@ test("load(String, Object, Function)", function() { ...@@ -1218,8 +1218,8 @@ test("load(String, Object, Function)", function() {
jQuery("<div />").load(url("data/params_html.php"), { foo: 3, bar: "ok" }, function() { jQuery("<div />").load(url("data/params_html.php"), { foo: 3, bar: "ok" }, function() {
var $post = jQuery(this).find("#post"); var $post = jQuery(this).find("#post");
equals( $post.find("#foo").text(), "3", "Check if a hash of data is passed correctly"); equal( $post.find("#foo").text(), "3", "Check if a hash of data is passed correctly");
equals( $post.find("#bar").text(), "ok", "Check if a hash of data is passed correctly"); equal( $post.find("#bar").text(), "ok", "Check if a hash of data is passed correctly");
start(); start();
}); });
}); });
...@@ -1230,8 +1230,8 @@ test("load(String, String, Function)", function() { ...@@ -1230,8 +1230,8 @@ test("load(String, String, Function)", function() {
jQuery("<div />").load(url("data/params_html.php"), "foo=3&bar=ok", function() { jQuery("<div />").load(url("data/params_html.php"), "foo=3&bar=ok", function() {
var $get = jQuery(this).find("#get"); var $get = jQuery(this).find("#get");
equals( $get.find("#foo").text(), "3", "Check if a string of data is passed correctly"); equal( $get.find("#foo").text(), "3", "Check if a string of data is passed correctly");
equals( $get.find("#bar").text(), "ok", "Check if a of data is passed correctly"); equal( $get.find("#bar").text(), "ok", "Check if a of data is passed correctly");
start(); start();
}); });
}); });
...@@ -1259,8 +1259,8 @@ test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", f ...@@ -1259,8 +1259,8 @@ test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", f
jQuery("tab", xml).each(function() { jQuery("tab", xml).each(function() {
content.push(jQuery(this).text()); content.push(jQuery(this).text());
}); });
equals( content[0], "blabla", "Check first tab"); equal( content[0], "blabla", "Check first tab");
equals( content[1], "blublu", "Check second tab"); equal( content[1], "blublu", "Check second tab");
start(); start();
}); });
}); });
...@@ -1269,7 +1269,7 @@ test("jQuery.getScript(String, Function) - with callback", function() { ...@@ -1269,7 +1269,7 @@ test("jQuery.getScript(String, Function) - with callback", function() {
expect(3); expect(3);
stop(); stop();
jQuery.getScript(url("data/test.js"), function( data, _, jqXHR ) { jQuery.getScript(url("data/test.js"), function( data, _, jqXHR ) {
equals( foobar, "bar", "Check if script was evaluated" ); equal( foobar, "bar", "Check if script was evaluated" );
strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script (#8082)" ); strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script (#8082)" );
setTimeout(start, 100); setTimeout(start, 100);
}); });
...@@ -1574,7 +1574,7 @@ test("jQuery.ajax() - script, Remote with POST", function() { ...@@ -1574,7 +1574,7 @@ test("jQuery.ajax() - script, Remote with POST", function() {
dataType: "script", dataType: "script",
success: function(data, status){ success: function(data, status){
ok( foobar, "Script results returned (POST, no callback)" ); ok( foobar, "Script results returned (POST, no callback)" );
equals( status, "success", "Script results returned (POST, no callback)" ); equal( status, "success", "Script results returned (POST, no callback)" );
start(); start();
}, },
error: function(xhr) { error: function(xhr) {
...@@ -1615,7 +1615,7 @@ test("jQuery.ajax() - malformed JSON", function() { ...@@ -1615,7 +1615,7 @@ test("jQuery.ajax() - malformed JSON", function() {
start(); start();
}, },
error: function(xhr, msg, detailedMsg) { error: function(xhr, msg, detailedMsg) {
equals( "parsererror", msg, "A parse error occurred." ); equal( "parsererror", msg, "A parse error occurred." );
ok( /^(Invalid|SyntaxError|exception)/i.test(detailedMsg), "Detailed parsererror message provided" ); ok( /^(Invalid|SyntaxError|exception)/i.test(detailedMsg), "Detailed parsererror message provided" );
start(); start();
} }
...@@ -1654,10 +1654,10 @@ test("jQuery.ajax() - json by content-type", function() { ...@@ -1654,10 +1654,10 @@ test("jQuery.ajax() - json by content-type", function() {
data: { header: "json", json: "array" }, data: { header: "json", json: "array" },
success: function( json ) { success: function( json ) {
ok( json.length >= 2, "Check length"); ok( json.length >= 2, "Check length");
equals( json[0].name, "John", "Check JSON: first, name" ); equal( json[0].name, "John", "Check JSON: first, name" );
equals( json[0].age, 21, "Check JSON: first, age" ); equal( json[0].age, 21, "Check JSON: first, age" );
equals( json[1].name, "Peter", "Check JSON: second, name" ); equal( json[1].name, "Peter", "Check JSON: second, name" );
equals( json[1].age, 25, "Check JSON: second, age" ); equal( json[1].age, 25, "Check JSON: second, age" );
start(); start();
} }
}); });
...@@ -1675,13 +1675,13 @@ test("jQuery.ajax() - json by content-type disabled with options", function() { ...@@ -1675,13 +1675,13 @@ test("jQuery.ajax() - json by content-type disabled with options", function() {
json: false json: false
}, },
success: function( text ) { success: function( text ) {
equals( typeof text , "string" , "json wasn't auto-determined" ); equal( typeof text , "string" , "json wasn't auto-determined" );
var json = jQuery.parseJSON( text ); var json = jQuery.parseJSON( text );
ok( json.length >= 2, "Check length"); ok( json.length >= 2, "Check length");
equals( json[0].name, "John", "Check JSON: first, name" ); equal( json[0].name, "John", "Check JSON: first, name" );
equals( json[0].age, 21, "Check JSON: first, age" ); equal( json[0].age, 21, "Check JSON: first, age" );
equals( json[1].name, "Peter", "Check JSON: second, name" ); equal( json[1].name, "Peter", "Check JSON: second, name" );
equals( json[1].age, 25, "Check JSON: second, age" ); equal( json[1].age, 25, "Check JSON: second, age" );
start(); start();
} }
}); });
...@@ -1692,10 +1692,10 @@ test("jQuery.getJSON(String, Hash, Function) - JSON array", function() { ...@@ -1692,10 +1692,10 @@ test("jQuery.getJSON(String, Hash, Function) - JSON array", function() {
stop(); stop();
jQuery.getJSON(url("data/json.php"), {json: "array"}, function(json) { jQuery.getJSON(url("data/json.php"), {json: "array"}, function(json) {
ok( json.length >= 2, "Check length"); ok( json.length >= 2, "Check length");
equals( json[0].name, "John", "Check JSON: first, name" ); equal( json[0].name, "John", "Check JSON: first, name" );
equals( json[0].age, 21, "Check JSON: first, age" ); equal( json[0].age, 21, "Check JSON: first, age" );
equals( json[1].name, "Peter", "Check JSON: second, name" ); equal( json[1].name, "Peter", "Check JSON: second, name" );
equals( json[1].age, 25, "Check JSON: second, age" ); equal( json[1].age, 25, "Check JSON: second, age" );
start(); start();
}); });
}); });
...@@ -1705,8 +1705,8 @@ test("jQuery.getJSON(String, Function) - JSON object", function() { ...@@ -1705,8 +1705,8 @@ test("jQuery.getJSON(String, Function) - JSON object", function() {
stop(); stop();
jQuery.getJSON(url("data/json.php"), function(json) { jQuery.getJSON(url("data/json.php"), function(json) {
if (json && json.data) { if (json && json.data) {
equals( json.data.lang, "en", "Check JSON: lang" ); equal( json.data.lang, "en", "Check JSON: lang" );
equals( json.data.length, 25, "Check JSON: length" ); equal( json.data.length, 25, "Check JSON: length" );
} }
start(); start();
}); });
...@@ -1726,7 +1726,7 @@ test("jQuery.getJSON - Using Native JSON", function() { ...@@ -1726,7 +1726,7 @@ test("jQuery.getJSON - Using Native JSON", function() {
stop(); stop();
jQuery.getJSON(url("data/json.php"), function(json) { jQuery.getJSON(url("data/json.php"), function(json) {
window.JSON = old; window.JSON = old;
equals( json, true, "Verifying return value" ); equal( json, true, "Verifying return value" );
start(); start();
}); });
}); });
...@@ -1738,8 +1738,8 @@ test("jQuery.getJSON(String, Function) - JSON object with absolute url to local ...@@ -1738,8 +1738,8 @@ test("jQuery.getJSON(String, Function) - JSON object with absolute url to local
stop(); stop();
jQuery.getJSON(url(base + "data/json.php"), function(json) { jQuery.getJSON(url(base + "data/json.php"), function(json) {
equals( json.data.lang, "en", "Check JSON: lang" ); equal( json.data.lang, "en", "Check JSON: lang" );
equals( json.data.length, 25, "Check JSON: length" ); equal( json.data.length, 25, "Check JSON: length" );
start(); start();
}); });
}); });
...@@ -1750,8 +1750,8 @@ test("jQuery.post - data", 3, function() { ...@@ -1750,8 +1750,8 @@ test("jQuery.post - data", 3, function() {
jQuery.when( jQuery.when(
jQuery.post( url( "data/name.php" ), { xml: "5-2", length: 3 }, function( xml ) { jQuery.post( url( "data/name.php" ), { xml: "5-2", length: 3 }, function( xml ) {
jQuery( "math", xml ).each(function() { jQuery( "math", xml ).each(function() {
equals( jQuery( "calculation", this ).text(), "5-2", "Check for XML" ); equal( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
equals( jQuery( "result", this ).text(), "3", "Check for XML" ); equal( jQuery( "result", this ).text(), "3", "Check for XML" );
}); });
}), }),
...@@ -1781,16 +1781,16 @@ test("jQuery.post(String, Hash, Function) - simple with xml", function() { ...@@ -1781,16 +1781,16 @@ test("jQuery.post(String, Hash, Function) - simple with xml", function() {
jQuery.post(url("data/name.php"), {xml: "5-2"}, function(xml){ jQuery.post(url("data/name.php"), {xml: "5-2"}, function(xml){
jQuery("math", xml).each(function() { jQuery("math", xml).each(function() {
equals( jQuery("calculation", this).text(), "5-2", "Check for XML" ); equal( jQuery("calculation", this).text(), "5-2", "Check for XML" );
equals( 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){
jQuery("math", xml).each(function() { jQuery("math", xml).each(function() {
equals( jQuery("calculation", this).text(), "5-2", "Check for XML" ); equal( jQuery("calculation", this).text(), "5-2", "Check for XML" );
equals( 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();
}); });
...@@ -1859,7 +1859,7 @@ test("jQuery.ajax - simple get", function() { ...@@ -1859,7 +1859,7 @@ test("jQuery.ajax - simple get", function() {
type: "GET", type: "GET",
url: url("data/name.php?name=foo"), url: url("data/name.php?name=foo"),
success: function(msg){ success: function(msg){
equals( msg, "bar", "Check for GET" ); equal( msg, "bar", "Check for GET" );
start(); start();
} }
}); });
...@@ -1873,7 +1873,7 @@ test("jQuery.ajax - simple post", function() { ...@@ -1873,7 +1873,7 @@ test("jQuery.ajax - simple post", function() {
url: url("data/name.php"), url: url("data/name.php"),
data: "name=peter", data: "name=peter",
success: function(msg){ success: function(msg){
equals( msg, "pan", "Check for POST" ); equal( msg, "pan", "Check for POST" );
start(); start();
} }
}); });
...@@ -1885,7 +1885,7 @@ test("ajaxSetup()", function() { ...@@ -1885,7 +1885,7 @@ test("ajaxSetup()", function() {
jQuery.ajaxSetup({ jQuery.ajaxSetup({
url: url("data/name.php?name=foo"), url: url("data/name.php?name=foo"),
success: function(msg){ success: function(msg){
equals( msg, "bar", "Check for GET" ); equal( msg, "bar", "Check for GET" );
start(); start();
} }
}); });
...@@ -1900,7 +1900,7 @@ test("custom timeout does not set error message when timeout occurs, see #970", ...@@ -1900,7 +1900,7 @@ test("custom timeout does not set error message when timeout occurs, see #970",
timeout: 500, timeout: 500,
error: function(request, status) { error: function(request, status) {
ok( status != null, "status shouldn't be null in error handler" ); ok( status != null, "status shouldn't be null in error handler" );
equals( "timeout", status ); equal( "timeout", status );
start(); start();
} }
}); });
...@@ -1917,7 +1917,7 @@ test("data option: evaluate function values (#2806)", function() { ...@@ -1917,7 +1917,7 @@ test("data option: evaluate function values (#2806)", function() {
} }
}, },
success: function(result) { success: function(result) {
equals( result, "key=value" ); equal( result, "key=value" );
start(); start();
} }
}); });
...@@ -1930,7 +1930,7 @@ test("data option: empty bodies for non-GET requests", function() { ...@@ -1930,7 +1930,7 @@ test("data option: empty bodies for non-GET requests", function() {
data: undefined, data: undefined,
type: "post", type: "post",
success: function(result) { success: function(result) {
equals( result, "" ); equal( result, "" );
start(); start();
} }
}); });
...@@ -1952,7 +1952,7 @@ jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache ...@@ -1952,7 +1952,7 @@ jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache
ifModified: true, ifModified: true,
cache: cache, cache: cache,
success: function(data, status) { success: function(data, status) {
equals(status, "success" ); equal(status, "success" );
jQuery.ajax({ jQuery.ajax({
url: url, url: url,
...@@ -1963,7 +1963,7 @@ jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache ...@@ -1963,7 +1963,7 @@ jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache
ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since')."); ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since')."); ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
} else { } else {
equals(status, "notmodified"); equal(status, "notmodified");
ok(data == null, "response body should be empty"); ok(data == null, "response body should be empty");
} }
start(); start();
...@@ -1979,7 +1979,7 @@ jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache ...@@ -1979,7 +1979,7 @@ jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache
}); });
}, },
error: function() { error: function() {
equals(false, "error"); equal(false, "error");
// Do this because opera simply refuses to implement 304 handling :( // Do this because opera simply refuses to implement 304 handling :(
// A feature-driven way of detecting this would be appreciated // A feature-driven way of detecting this would be appreciated
// See: http://gist.github.com/599419 // See: http://gist.github.com/599419
...@@ -2001,7 +2001,7 @@ jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache ...@@ -2001,7 +2001,7 @@ jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache
ifModified: true, ifModified: true,
cache: cache, cache: cache,
success: function(data, status) { success: function(data, status) {
equals(status, "success" ); equal(status, "success" );
jQuery.ajax({ jQuery.ajax({
url: url, url: url,
...@@ -2012,7 +2012,7 @@ jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache ...@@ -2012,7 +2012,7 @@ jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache
ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-None-Match')."); ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-None-Match')."); ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
} else { } else {
equals(status, "notmodified"); equal(status, "notmodified");
ok(data == null, "response body should be empty"); ok(data == null, "response body should be empty");
} }
start(); start();
......
...@@ -36,21 +36,21 @@ test("jQuery.propFix integrity test", function() { ...@@ -36,21 +36,21 @@ test("jQuery.propFix integrity test", function() {
test("attr(String)", function() { test("attr(String)", function() {
expect(46); expect(46);
equals( jQuery("#text1").attr("type"), "text", "Check for type attribute" ); equal( jQuery("#text1").attr("type"), "text", "Check for type attribute" );
equals( jQuery("#radio1").attr("type"), "radio", "Check for type attribute" ); equal( jQuery("#radio1").attr("type"), "radio", "Check for type attribute" );
equals( jQuery("#check1").attr("type"), "checkbox", "Check for type attribute" ); equal( jQuery("#check1").attr("type"), "checkbox", "Check for type attribute" );
equals( jQuery("#simon1").attr("rel"), "bookmark", "Check for rel attribute" ); equal( jQuery("#simon1").attr("rel"), "bookmark", "Check for rel attribute" );
equals( jQuery("#google").attr("title"), "Google!", "Check for title attribute" ); equal( jQuery("#google").attr("title"), "Google!", "Check for title attribute" );
equals( jQuery("#mark").attr("hreflang"), "en", "Check for hreflang attribute" ); equal( jQuery("#mark").attr("hreflang"), "en", "Check for hreflang attribute" );
equals( jQuery("#en").attr("lang"), "en", "Check for lang attribute" ); equal( jQuery("#en").attr("lang"), "en", "Check for lang attribute" );
equals( jQuery("#simon").attr("class"), "blog link", "Check for class attribute" ); equal( jQuery("#simon").attr("class"), "blog link", "Check for class attribute" );
equals( jQuery("#name").attr("name"), "name", "Check for name attribute" ); equal( jQuery("#name").attr("name"), "name", "Check for name attribute" );
equals( jQuery("#text1").attr("name"), "action", "Check for name attribute" ); equal( jQuery("#text1").attr("name"), "action", "Check for name attribute" );
ok( jQuery("#form").attr("action").indexOf("formaction") >= 0, "Check for action attribute" ); ok( jQuery("#form").attr("action").indexOf("formaction") >= 0, "Check for action attribute" );
equals( jQuery("#text1").attr("value", "t").attr("value"), "t", "Check setting the value attribute" ); equal( jQuery("#text1").attr("value", "t").attr("value"), "t", "Check setting the value attribute" );
equals( jQuery("<div value='t'></div>").attr("value"), "t", "Check setting custom attr named 'value' on a div" ); equal( jQuery("<div value='t'></div>").attr("value"), "t", "Check setting custom attr named 'value' on a div" );
equals( jQuery("#form").attr("blah", "blah").attr("blah"), "blah", "Set non-existant attribute on a form" ); equal( jQuery("#form").attr("blah", "blah").attr("blah"), "blah", "Set non-existant attribute on a form" );
equals( jQuery("#foo").attr("height"), undefined, "Non existent height attribute should return undefined" ); equal( jQuery("#foo").attr("height"), undefined, "Non existent height attribute should return undefined" );
// [7472] & [3113] (form contains an input with name="action" or name="id") // [7472] & [3113] (form contains an input with name="action" or name="id")
var extras = jQuery("<input name='id' name='name' /><input id='target' name='target' />").appendTo("#testForm"); var extras = jQuery("<input name='id' name='name' /><input id='target' name='target' />").appendTo("#testForm");
...@@ -59,20 +59,20 @@ test("attr(String)", function() { ...@@ -59,20 +59,20 @@ test("attr(String)", function() {
equal( jQuery("#testForm").attr("target", "newTarget").attr("target"), "newTarget", "Set target successfully on a form" ); equal( jQuery("#testForm").attr("target", "newTarget").attr("target"), "newTarget", "Set target successfully on a form" );
equal( jQuery("#testForm").removeAttr("id").attr("id"), undefined, "Retrieving id does not equal the input with name=id after id is removed [#7472]" ); equal( jQuery("#testForm").removeAttr("id").attr("id"), undefined, "Retrieving id does not equal the input with name=id after id is removed [#7472]" );
// Bug #3685 (form contains input with name="name") // Bug #3685 (form contains input with name="name")
equals( jQuery("#testForm").attr("name"), undefined, "Retrieving name does not retrieve input with name=name" ); equal( jQuery("#testForm").attr("name"), undefined, "Retrieving name does not retrieve input with name=name" );
extras.remove(); extras.remove();
equals( jQuery("#text1").attr("maxlength"), "30", "Check for maxlength attribute" ); equal( jQuery("#text1").attr("maxlength"), "30", "Check for maxlength attribute" );
equals( jQuery("#text1").attr("maxLength"), "30", "Check for maxLength attribute" ); equal( jQuery("#text1").attr("maxLength"), "30", "Check for maxLength attribute" );
equals( jQuery("#area1").attr("maxLength"), "30", "Check for maxLength attribute" ); equal( jQuery("#area1").attr("maxLength"), "30", "Check for maxLength attribute" );
// using innerHTML in IE causes href attribute to be serialized to the full path // using innerHTML in IE causes href attribute to be serialized to the full path
jQuery("<a/>").attr({ "id": "tAnchor5", "href": "#5" }).appendTo("#qunit-fixture"); jQuery("<a/>").attr({ "id": "tAnchor5", "href": "#5" }).appendTo("#qunit-fixture");
equals( jQuery("#tAnchor5").attr("href"), "#5", "Check for non-absolute href (an anchor)" ); equal( jQuery("#tAnchor5").attr("href"), "#5", "Check for non-absolute href (an anchor)" );
// list attribute is readonly by default in browsers that support it // list attribute is readonly by default in browsers that support it
jQuery("#list-test").attr("list", "datalist"); jQuery("#list-test").attr("list", "datalist");
equals( jQuery("#list-test").attr("list"), "datalist", "Check setting list attribute" ); equal( jQuery("#list-test").attr("list"), "datalist", "Check setting list attribute" );
// Related to [5574] and [5683] // Related to [5574] and [5683]
var body = document.body, $body = jQuery(body); var body = document.body, $body = jQuery(body);
...@@ -80,10 +80,10 @@ test("attr(String)", function() { ...@@ -80,10 +80,10 @@ test("attr(String)", function() {
strictEqual( $body.attr("foo"), undefined, "Make sure that a non existent attribute returns undefined" ); strictEqual( $body.attr("foo"), undefined, "Make sure that a non existent attribute returns undefined" );
body.setAttribute("foo", "baz"); body.setAttribute("foo", "baz");
equals( $body.attr("foo"), "baz", "Make sure the dom attribute is retrieved when no expando is found" ); equal( $body.attr("foo"), "baz", "Make sure the dom attribute is retrieved when no expando is found" );
$body.attr("foo","cool"); $body.attr("foo","cool");
equals( $body.attr("foo"), "cool", "Make sure that setting works well when both expando and dom attribute are available" ); equal( $body.attr("foo"), "cool", "Make sure that setting works well when both expando and dom attribute are available" );
body.removeAttribute("foo"); // Cleanup body.removeAttribute("foo"); // Cleanup
...@@ -94,8 +94,8 @@ test("attr(String)", function() { ...@@ -94,8 +94,8 @@ test("attr(String)", function() {
equal( jQuery( option ).attr("selected"), "selected", "Make sure that a single option is selected, even when in an optgroup." ); equal( jQuery( option ).attr("selected"), "selected", "Make sure that a single option is selected, even when in an optgroup." );
var $img = jQuery("<img style='display:none' width='215' height='53' src='http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif'/>").appendTo("body"); var $img = jQuery("<img style='display:none' width='215' height='53' src='http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif'/>").appendTo("body");
equals( $img.attr("width"), "215", "Retrieve width attribute an an element with display:none." ); equal( $img.attr("width"), "215", "Retrieve width attribute an an element with display:none." );
equals( $img.attr("height"), "53", "Retrieve height attribute an an element with display:none." ); equal( $img.attr("height"), "53", "Retrieve height attribute an an element with display:none." );
// Check for style support // Check for style support
ok( !!~jQuery("#dl").attr("style").indexOf("position"), "Check style attribute getter, also normalize css props to lowercase" ); ok( !!~jQuery("#dl").attr("style").indexOf("position"), "Check style attribute getter, also normalize css props to lowercase" );
...@@ -103,12 +103,12 @@ test("attr(String)", function() { ...@@ -103,12 +103,12 @@ test("attr(String)", function() {
// Check value on button element (#1954) // Check value on button element (#1954)
var $button = jQuery("<button value='foobar'>text</button>").insertAfter("#button"); var $button = jQuery("<button value='foobar'>text</button>").insertAfter("#button");
equals( $button.attr("value"), "foobar", "Value retrieval on a button does not return innerHTML" ); equal( $button.attr("value"), "foobar", "Value retrieval on a button does not return innerHTML" );
equals( $button.attr("value", "baz").html(), "text", "Setting the value does not change innerHTML" ); equal( $button.attr("value", "baz").html(), "text", "Setting the value does not change innerHTML" );
// Attributes with a colon on a table element (#1591) // Attributes with a colon on a table element (#1591)
equals( jQuery("#table").attr("test:attrib"), undefined, "Retrieving a non-existent attribute on a table with a colon does not throw an error." ); equal( jQuery("#table").attr("test:attrib"), undefined, "Retrieving a non-existent attribute on a table with a colon does not throw an error." );
equals( jQuery("#table").attr("test:attrib", "foobar").attr("test:attrib"), "foobar", "Setting an attribute on a table with a colon does not throw an error." ); equal( jQuery("#table").attr("test:attrib", "foobar").attr("test:attrib"), "foobar", "Setting an attribute on a table with a colon does not throw an error." );
var $form = jQuery("<form class='something'></form>").appendTo("#qunit-fixture"); var $form = jQuery("<form class='something'></form>").appendTo("#qunit-fixture");
equal( $form.attr("class"), "something", "Retrieve the class attribute on a form." ); equal( $form.attr("class"), "something", "Retrieve the class attribute on a form." );
...@@ -142,8 +142,8 @@ if ( !isLocal ) { ...@@ -142,8 +142,8 @@ if ( !isLocal ) {
test("attr(String, Function)", function() { test("attr(String, Function)", function() {
expect(2); expect(2);
equals( jQuery("#text1").attr("value", function() { return this.id; })[0].value, "text1", "Set value from id" ); equal( jQuery("#text1").attr("value", function() { return this.id; })[0].value, "text1", "Set value from id" );
equals( jQuery("#text1").attr("title", function(i) { return i; }).attr("title"), "0", "Set value with an index"); equal( jQuery("#text1").attr("title", function(i) { return i; }).attr("title"), "0", "Set value with an index");
}); });
test("attr(Hash)", function() { test("attr(Hash)", function() {
...@@ -153,8 +153,8 @@ test("attr(Hash)", function() { ...@@ -153,8 +153,8 @@ test("attr(Hash)", 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" );
equals( 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" );
equals( jQuery("#text1").attr({title: function(i) { return i; }}).attr("title"), "0", "Set attribute to computed value #2"); equal( jQuery("#text1").attr({title: function(i) { return i; }}).attr("title"), "0", "Set attribute to computed value #2");
}); });
test("attr(String, Object)", function() { test("attr(String, Object)", function() {
...@@ -170,43 +170,43 @@ test("attr(String, Object)", function() { ...@@ -170,43 +170,43 @@ test("attr(String, Object)", function() {
} }
} }
equals( fail, false, "Set Attribute, the #" + fail + " element didn't get the attribute 'foo'" ); equal( fail, false, "Set Attribute, the #" + fail + " element didn't get the attribute 'foo'" );
ok( jQuery("#foo").attr({ "width": null }), "Try to set an attribute to nothing" ); ok( jQuery("#foo").attr({ "width": null }), "Try to set an attribute to nothing" );
jQuery("#name").attr("name", "something"); jQuery("#name").attr("name", "something");
equals( jQuery("#name").attr("name"), "something", "Set name attribute" ); equal( jQuery("#name").attr("name"), "something", "Set name attribute" );
jQuery("#name").attr("name", null); jQuery("#name").attr("name", null);
equals( jQuery("#name").attr("name"), undefined, "Remove name attribute" ); equal( jQuery("#name").attr("name"), undefined, "Remove name attribute" );
var $input = jQuery("<input>", { name: "something", id: "specified" }); var $input = jQuery("<input>", { name: "something", id: "specified" });
equal( $input.attr("name"), "something", "Check element creation gets/sets the name attribute." ); equal( $input.attr("name"), "something", "Check element creation gets/sets the name attribute." );
equal( $input.attr("id"), "specified", "Check element creation gets/sets the id attribute." ); equal( $input.attr("id"), "specified", "Check element creation gets/sets the id attribute." );
jQuery("#check2").prop("checked", true).prop("checked", false).attr("checked", true); jQuery("#check2").prop("checked", true).prop("checked", false).attr("checked", true);
equals( document.getElementById("check2").checked, true, "Set checked attribute" ); equal( document.getElementById("check2").checked, true, "Set checked attribute" );
equals( jQuery("#check2").prop("checked"), true, "Set checked attribute" ); equal( jQuery("#check2").prop("checked"), true, "Set checked attribute" );
equals( jQuery("#check2").attr("checked"), "checked", "Set checked attribute" ); equal( jQuery("#check2").attr("checked"), "checked", "Set checked attribute" );
jQuery("#check2").attr("checked", false); jQuery("#check2").attr("checked", false);
equals( document.getElementById("check2").checked, false, "Set checked attribute" ); equal( document.getElementById("check2").checked, false, "Set checked attribute" );
equals( jQuery("#check2").prop("checked"), false, "Set checked attribute" ); equal( jQuery("#check2").prop("checked"), false, "Set checked attribute" );
equals( jQuery("#check2").attr("checked"), undefined, "Set checked attribute" ); equal( jQuery("#check2").attr("checked"), undefined, "Set checked attribute" );
jQuery("#text1").attr("readonly", true); jQuery("#text1").attr("readonly", true);
equals( document.getElementById("text1").readOnly, true, "Set readonly attribute" ); equal( document.getElementById("text1").readOnly, true, "Set readonly attribute" );
equals( jQuery("#text1").prop("readOnly"), true, "Set readonly attribute" ); equal( jQuery("#text1").prop("readOnly"), true, "Set readonly attribute" );
equals( jQuery("#text1").attr("readonly"), "readonly", "Set readonly attribute" ); equal( jQuery("#text1").attr("readonly"), "readonly", "Set readonly attribute" );
jQuery("#text1").attr("readonly", false); jQuery("#text1").attr("readonly", false);
equals( document.getElementById("text1").readOnly, false, "Set readonly attribute" ); equal( document.getElementById("text1").readOnly, false, "Set readonly attribute" );
equals( jQuery("#text1").prop("readOnly"), false, "Set readonly attribute" ); equal( jQuery("#text1").prop("readOnly"), false, "Set readonly attribute" );
equals( jQuery("#text1").attr("readonly"), undefined, "Set readonly attribute" ); equal( jQuery("#text1").attr("readonly"), undefined, "Set readonly attribute" );
jQuery("#check2").prop("checked", true); jQuery("#check2").prop("checked", true);
equals( document.getElementById("check2").checked, true, "Set checked attribute" ); equal( document.getElementById("check2").checked, true, "Set checked attribute" );
equals( jQuery("#check2").prop("checked"), true, "Set checked attribute" ); equal( jQuery("#check2").prop("checked"), true, "Set checked attribute" );
equals( jQuery("#check2").attr("checked"), "checked", "Set checked attribute" ); equal( jQuery("#check2").attr("checked"), "checked", "Set checked attribute" );
jQuery("#check2").prop("checked", false); jQuery("#check2").prop("checked", false);
equals( document.getElementById("check2").checked, false, "Set checked attribute" ); equal( document.getElementById("check2").checked, false, "Set checked attribute" );
equals( jQuery("#check2").prop("checked"), false, "Set checked attribute" ); equal( jQuery("#check2").prop("checked"), false, "Set checked attribute" );
equals( jQuery("#check2").attr("checked"), undefined, "Set checked attribute" ); equal( jQuery("#check2").attr("checked"), undefined, "Set checked attribute" );
jQuery("#check2").attr("checked", "checked"); jQuery("#check2").attr("checked", "checked");
equal( document.getElementById("check2").checked, true, "Set checked attribute with 'checked'" ); equal( document.getElementById("check2").checked, true, "Set checked attribute with 'checked'" );
...@@ -221,18 +221,18 @@ test("attr(String, Object)", function() { ...@@ -221,18 +221,18 @@ test("attr(String, Object)", function() {
equal( $radios.attr("checked"), $radios[0].checked ? "checked" : undefined, "Known booleans do not fall back to attribute presence (#10278)"); equal( $radios.attr("checked"), $radios[0].checked ? "checked" : undefined, "Known booleans do not fall back to attribute presence (#10278)");
jQuery("#text1").prop("readOnly", true); jQuery("#text1").prop("readOnly", true);
equals( document.getElementById("text1").readOnly, true, "Set readonly attribute" ); equal( document.getElementById("text1").readOnly, true, "Set readonly attribute" );
equals( jQuery("#text1").prop("readOnly"), true, "Set readonly attribute" ); equal( jQuery("#text1").prop("readOnly"), true, "Set readonly attribute" );
equals( jQuery("#text1").attr("readonly"), "readonly", "Set readonly attribute" ); equal( jQuery("#text1").attr("readonly"), "readonly", "Set readonly attribute" );
jQuery("#text1").prop("readOnly", false); jQuery("#text1").prop("readOnly", false);
equals( document.getElementById("text1").readOnly, false, "Set readonly attribute" ); equal( document.getElementById("text1").readOnly, false, "Set readonly attribute" );
equals( jQuery("#text1").prop("readOnly"), false, "Set readonly attribute" ); equal( jQuery("#text1").prop("readOnly"), false, "Set readonly attribute" );
equals( jQuery("#text1").attr("readonly"), undefined, "Set readonly attribute" ); equal( jQuery("#text1").attr("readonly"), undefined, "Set readonly attribute" );
jQuery("#name").attr("maxlength", "5"); jQuery("#name").attr("maxlength", "5");
equals( document.getElementById("name").maxLength, 5, "Set maxlength attribute" ); equal( document.getElementById("name").maxLength, 5, "Set maxlength attribute" );
jQuery("#name").attr("maxLength", "10"); jQuery("#name").attr("maxLength", "10");
equals( document.getElementById("name").maxLength, 10, "Set maxlength attribute" ); equal( document.getElementById("name").maxLength, 10, "Set maxlength attribute" );
// HTML5 boolean attributes // HTML5 boolean attributes
var $text = jQuery("#text1").attr({ var $text = jQuery("#text1").attr({
...@@ -258,7 +258,7 @@ test("attr(String, Object)", function() { ...@@ -258,7 +258,7 @@ test("attr(String, Object)", function() {
$text.removeData("something").removeData("another").removeAttr("aria-disabled"); $text.removeData("something").removeData("another").removeAttr("aria-disabled");
jQuery("#foo").attr("contenteditable", true); jQuery("#foo").attr("contenteditable", true);
equals( jQuery("#foo").attr("contenteditable"), "true", "Enumerated attributes are set properly" ); equal( jQuery("#foo").attr("contenteditable"), "true", "Enumerated attributes are set properly" );
var attributeNode = document.createAttribute("irrelevant"), var attributeNode = document.createAttribute("irrelevant"),
commentNode = document.createComment("some comment"), commentNode = document.createComment("some comment"),
...@@ -280,27 +280,27 @@ test("attr(String, Object)", function() { ...@@ -280,27 +280,27 @@ test("attr(String, Object)", function() {
var table = jQuery("#table").append("<tr><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr>"), var table = jQuery("#table").append("<tr><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr>"),
td = table.find("td:first"); td = table.find("td:first");
td.attr("rowspan", "2"); td.attr("rowspan", "2");
equals( td[0].rowSpan, 2, "Check rowspan is correctly set" ); equal( td[0].rowSpan, 2, "Check rowspan is correctly set" );
td.attr("colspan", "2"); td.attr("colspan", "2");
equals( td[0].colSpan, 2, "Check colspan is correctly set" ); equal( td[0].colSpan, 2, "Check colspan is correctly set" );
table.attr("cellspacing", "2"); table.attr("cellspacing", "2");
equals( table[0].cellSpacing, "2", "Check cellspacing is correctly set" ); equal( table[0].cellSpacing, "2", "Check cellspacing is correctly set" );
equals( jQuery("#area1").attr("value"), "foobar", "Value attribute retrieves the property for backwards compatibility." ); equal( jQuery("#area1").attr("value"), "foobar", "Value attribute retrieves the property for backwards compatibility." );
// for #1070 // for #1070
jQuery("#name").attr("someAttr", "0"); jQuery("#name").attr("someAttr", "0");
equals( jQuery("#name").attr("someAttr"), "0", "Set attribute to a string of \"0\"" ); equal( jQuery("#name").attr("someAttr"), "0", "Set attribute to a string of \"0\"" );
jQuery("#name").attr("someAttr", 0); jQuery("#name").attr("someAttr", 0);
equals( jQuery("#name").attr("someAttr"), "0", "Set attribute to the number 0" ); equal( jQuery("#name").attr("someAttr"), "0", "Set attribute to the number 0" );
jQuery("#name").attr("someAttr", 1); jQuery("#name").attr("someAttr", 1);
equals( jQuery("#name").attr("someAttr"), "1", "Set attribute to the number 1" ); equal( jQuery("#name").attr("someAttr"), "1", "Set attribute to the number 1" );
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents(); var j = jQuery("#nonnodes").contents();
j.attr("name", "attrvalue"); j.attr("name", "attrvalue");
equals( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" ); equal( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" );
j.removeAttr("name"); j.removeAttr("name");
// Type // Type
...@@ -312,7 +312,7 @@ test("attr(String, Object)", function() { ...@@ -312,7 +312,7 @@ test("attr(String, Object)", function() {
thrown = true; thrown = true;
} }
ok( thrown, "Exception thrown when trying to change type property" ); ok( thrown, "Exception thrown when trying to change type property" );
equals( type, jQuery("#check2").attr("type"), "Verify that you can't change the type of an input element" ); equal( type, jQuery("#check2").attr("type"), "Verify that you can't change the type of an input element" );
var check = document.createElement("input"); var check = document.createElement("input");
thrown = true; thrown = true;
...@@ -322,7 +322,7 @@ test("attr(String, Object)", function() { ...@@ -322,7 +322,7 @@ test("attr(String, Object)", function() {
thrown = false; thrown = false;
} }
ok( thrown, "Exception thrown when trying to change type property" ); ok( thrown, "Exception thrown when trying to change type property" );
equals( "checkbox", jQuery(check).attr("type"), "Verify that you can change the type of an input element that isn't in the DOM" ); equal( "checkbox", jQuery(check).attr("type"), "Verify that you can change the type of an input element that isn't in the DOM" );
check = jQuery("<input />"); check = jQuery("<input />");
thrown = true; thrown = true;
...@@ -332,7 +332,7 @@ test("attr(String, Object)", function() { ...@@ -332,7 +332,7 @@ test("attr(String, Object)", function() {
thrown = false; thrown = false;
} }
ok( thrown, "Exception thrown when trying to change type property" ); ok( thrown, "Exception thrown when trying to change type property" );
equals( "checkbox", check.attr("type"), "Verify that you can change the type of an input element that isn't in the DOM" ); equal( "checkbox", check.attr("type"), "Verify that you can change the type of an input element that isn't in the DOM" );
var button = jQuery("#button"); var button = jQuery("#button");
thrown = false; thrown = false;
...@@ -342,16 +342,16 @@ test("attr(String, Object)", function() { ...@@ -342,16 +342,16 @@ test("attr(String, Object)", function() {
thrown = true; thrown = true;
} }
ok( thrown, "Exception thrown when trying to change type property" ); ok( thrown, "Exception thrown when trying to change type property" );
equals( "button", button.attr("type"), "Verify that you can't change the type of a button element" ); equal( "button", button.attr("type"), "Verify that you can't change the type of a button element" );
var $radio = jQuery("<input>", { "value": "sup", "type": "radio" }).appendTo("#testForm"); var $radio = jQuery("<input>", { "value": "sup", "type": "radio" }).appendTo("#testForm");
equals( $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("<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' baseProfile='full' width='200' height='200'>"
+ "<circle cx='200' cy='200' r='150' />" + "<circle cx='200' cy='200' r='150' />"
+ "</svg>").appendTo("body"); + "</svg>").appendTo("body");
equals( $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();
}); });
...@@ -363,16 +363,16 @@ test("attr(jquery_method)", function(){ ...@@ -363,16 +363,16 @@ test("attr(jquery_method)", function(){
// one at a time // one at a time
$elem.attr({html: "foo"}, true); $elem.attr({html: "foo"}, true);
equals( elem.innerHTML, "foo", "attr(html)"); equal( elem.innerHTML, "foo", "attr(html)");
$elem.attr({text: "bar"}, true); $elem.attr({text: "bar"}, true);
equals( elem.innerHTML, "bar", "attr(text)"); equal( elem.innerHTML, "bar", "attr(text)");
$elem.attr({css: {color: "red"}}, true); $elem.attr({css: {color: "red"}}, true);
ok( /^(#ff0000|red)$/i.test(elem.style.color), "attr(css)"); ok( /^(#ff0000|red)$/i.test(elem.style.color), "attr(css)");
$elem.attr({height: 10}, true); $elem.attr({height: 10}, true);
equals( elem.style.height, "10px", "attr(height)"); equal( elem.style.height, "10px", "attr(height)");
// Multiple attributes // Multiple attributes
...@@ -381,9 +381,9 @@ test("attr(jquery_method)", function(){ ...@@ -381,9 +381,9 @@ test("attr(jquery_method)", function(){
css:{ paddingLeft:1, paddingRight:1 } css:{ paddingLeft:1, paddingRight:1 }
}, true); }, true);
equals( elem.style.width, "10px", "attr({...})"); equal( elem.style.width, "10px", "attr({...})");
equals( elem.style.paddingLeft, "1px", "attr({...})"); equal( elem.style.paddingLeft, "1px", "attr({...})");
equals( elem.style.paddingRight, "1px", "attr({...})"); equal( elem.style.paddingRight, "1px", "attr({...})");
}); });
if ( !isLocal ) { if ( !isLocal ) {
...@@ -395,8 +395,8 @@ if ( !isLocal ) { ...@@ -395,8 +395,8 @@ if ( !isLocal ) {
jQuery( "tab", xml ).each(function() { jQuery( "tab", xml ).each(function() {
titles.push( jQuery(this).attr("title") ); titles.push( jQuery(this).attr("title") );
}); });
equals( titles[0], "Location", "attr() in XML context: Check first title" ); equal( titles[0], "Location", "attr() in XML context: Check first title" );
equals( titles[1], "Users", "attr() in XML context: Check second title" ); equal( titles[1], "Users", "attr() in XML context: Check second title" );
start(); start();
}); });
}); });
...@@ -406,55 +406,55 @@ test("attr('tabindex')", function() { ...@@ -406,55 +406,55 @@ test("attr('tabindex')", function() {
expect(8); expect(8);
// elements not natively tabbable // elements not natively tabbable
equals(jQuery("#listWithTabIndex").attr("tabindex"), 5, "not natively tabbable, with tabindex set to 0"); equal(jQuery("#listWithTabIndex").attr("tabindex"), 5, "not natively tabbable, with tabindex set to 0");
equals(jQuery("#divWithNoTabIndex").attr("tabindex"), undefined, "not natively tabbable, no tabindex set"); equal(jQuery("#divWithNoTabIndex").attr("tabindex"), undefined, "not natively tabbable, no tabindex set");
// anchor with href // anchor with href
equals(jQuery("#linkWithNoTabIndex").attr("tabindex"), 0, "anchor with href, no tabindex set"); equal(jQuery("#linkWithNoTabIndex").attr("tabindex"), 0, "anchor with href, no tabindex set");
equals(jQuery("#linkWithTabIndex").attr("tabindex"), 2, "anchor with href, tabindex set to 2"); equal(jQuery("#linkWithTabIndex").attr("tabindex"), 2, "anchor with href, tabindex set to 2");
equals(jQuery("#linkWithNegativeTabIndex").attr("tabindex"), -1, "anchor with href, tabindex set to -1"); equal(jQuery("#linkWithNegativeTabIndex").attr("tabindex"), -1, "anchor with href, tabindex set to -1");
// anchor without href // anchor without href
equals(jQuery("#linkWithNoHrefWithNoTabIndex").attr("tabindex"), undefined, "anchor without href, no tabindex set"); equal(jQuery("#linkWithNoHrefWithNoTabIndex").attr("tabindex"), undefined, "anchor without href, no tabindex set");
equals(jQuery("#linkWithNoHrefWithTabIndex").attr("tabindex"), 1, "anchor without href, tabindex set to 2"); equal(jQuery("#linkWithNoHrefWithTabIndex").attr("tabindex"), 1, "anchor without href, tabindex set to 2");
equals(jQuery("#linkWithNoHrefWithNegativeTabIndex").attr("tabindex"), -1, "anchor without href, no tabindex set"); equal(jQuery("#linkWithNoHrefWithNegativeTabIndex").attr("tabindex"), -1, "anchor without href, no tabindex set");
}); });
test("attr('tabindex', value)", function() { test("attr('tabindex', value)", function() {
expect(9); expect(9);
var element = jQuery("#divWithNoTabIndex"); var element = jQuery("#divWithNoTabIndex");
equals(element.attr("tabindex"), undefined, "start with no tabindex"); equal(element.attr("tabindex"), undefined, "start with no tabindex");
// set a positive string // set a positive string
element.attr("tabindex", "1"); element.attr("tabindex", "1");
equals(element.attr("tabindex"), 1, "set tabindex to 1 (string)"); equal(element.attr("tabindex"), 1, "set tabindex to 1 (string)");
// set a zero string // set a zero string
element.attr("tabindex", "0"); element.attr("tabindex", "0");
equals(element.attr("tabindex"), 0, "set tabindex to 0 (string)"); equal(element.attr("tabindex"), 0, "set tabindex to 0 (string)");
// set a negative string // set a negative string
element.attr("tabindex", "-1"); element.attr("tabindex", "-1");
equals(element.attr("tabindex"), -1, "set tabindex to -1 (string)"); equal(element.attr("tabindex"), -1, "set tabindex to -1 (string)");
// set a positive number // set a positive number
element.attr("tabindex", 1); element.attr("tabindex", 1);
equals(element.attr("tabindex"), 1, "set tabindex to 1 (number)"); equal(element.attr("tabindex"), 1, "set tabindex to 1 (number)");
// set a zero number // set a zero number
element.attr("tabindex", 0); element.attr("tabindex", 0);
equals(element.attr("tabindex"), 0, "set tabindex to 0 (number)"); equal(element.attr("tabindex"), 0, "set tabindex to 0 (number)");
// set a negative number // set a negative number
element.attr("tabindex", -1); element.attr("tabindex", -1);
equals(element.attr("tabindex"), -1, "set tabindex to -1 (number)"); equal(element.attr("tabindex"), -1, "set tabindex to -1 (number)");
element = jQuery("#linkWithTabIndex"); element = jQuery("#linkWithTabIndex");
equals(element.attr("tabindex"), 2, "start with tabindex 2"); equal(element.attr("tabindex"), 2, "start with tabindex 2");
element.attr("tabindex", -1); element.attr("tabindex", -1);
equals(element.attr("tabindex"), -1, "set negative tabindex"); equal(element.attr("tabindex"), -1, "set negative tabindex");
}); });
test("removeAttr(String)", function() { test("removeAttr(String)", function() {
...@@ -484,32 +484,32 @@ test("removeAttr(String)", function() { ...@@ -484,32 +484,32 @@ test("removeAttr(String)", function() {
test("prop(String, Object)", function() { test("prop(String, Object)", function() {
expect(31); expect(31);
equals( jQuery("#text1").prop("value"), "Test", "Check for value attribute" ); equal( jQuery("#text1").prop("value"), "Test", "Check for value attribute" );
equals( jQuery("#text1").prop("value", "Test2").prop("defaultValue"), "Test", "Check for defaultValue attribute" ); equal( jQuery("#text1").prop("value", "Test2").prop("defaultValue"), "Test", "Check for defaultValue attribute" );
equals( jQuery("#select2").prop("selectedIndex"), 3, "Check for selectedIndex attribute" ); equal( jQuery("#select2").prop("selectedIndex"), 3, "Check for selectedIndex attribute" );
equals( jQuery("#foo").prop("nodeName").toUpperCase(), "DIV", "Check for nodeName attribute" ); equal( jQuery("#foo").prop("nodeName").toUpperCase(), "DIV", "Check for nodeName attribute" );
equals( jQuery("#foo").prop("tagName").toUpperCase(), "DIV", "Check for tagName attribute" ); equal( jQuery("#foo").prop("tagName").toUpperCase(), "DIV", "Check for tagName attribute" );
equals( jQuery("<option/>").prop("selected"), false, "Check selected attribute on disconnected element." ); equal( jQuery("<option/>").prop("selected"), false, "Check selected attribute on disconnected element." );
equals( jQuery("#listWithTabIndex").prop("tabindex"), 5, "Check retrieving tabindex" ); equal( jQuery("#listWithTabIndex").prop("tabindex"), 5, "Check retrieving tabindex" );
jQuery("#text1").prop("readonly", true); jQuery("#text1").prop("readonly", true);
equals( document.getElementById("text1").readOnly, true, "Check setting readOnly property with 'readonly'" ); equal( document.getElementById("text1").readOnly, true, "Check setting readOnly property with 'readonly'" );
equals( jQuery("#label-for").prop("for"), "action", "Check retrieving htmlFor" ); equal( jQuery("#label-for").prop("for"), "action", "Check retrieving htmlFor" );
jQuery("#text1").prop("class", "test"); jQuery("#text1").prop("class", "test");
equals( document.getElementById("text1").className, "test", "Check setting className with 'class'" ); equal( document.getElementById("text1").className, "test", "Check setting className with 'class'" );
equals( jQuery("#text1").prop("maxlength"), 30, "Check retrieving maxLength" ); equal( jQuery("#text1").prop("maxlength"), 30, "Check retrieving maxLength" );
jQuery("#table").prop("cellspacing", 1); jQuery("#table").prop("cellspacing", 1);
equals( jQuery("#table").prop("cellSpacing"), "1", "Check setting and retrieving cellSpacing" ); equal( jQuery("#table").prop("cellSpacing"), "1", "Check setting and retrieving cellSpacing" );
jQuery("#table").prop("cellpadding", 1); jQuery("#table").prop("cellpadding", 1);
equals( jQuery("#table").prop("cellPadding"), "1", "Check setting and retrieving cellPadding" ); equal( jQuery("#table").prop("cellPadding"), "1", "Check setting and retrieving cellPadding" );
jQuery("#table").prop("rowspan", 1); jQuery("#table").prop("rowspan", 1);
equals( jQuery("#table").prop("rowSpan"), 1, "Check setting and retrieving rowSpan" ); equal( jQuery("#table").prop("rowSpan"), 1, "Check setting and retrieving rowSpan" );
jQuery("#table").prop("colspan", 1); jQuery("#table").prop("colspan", 1);
equals( jQuery("#table").prop("colSpan"), 1, "Check setting and retrieving colSpan" ); equal( jQuery("#table").prop("colSpan"), 1, "Check setting and retrieving colSpan" );
jQuery("#table").prop("usemap", 1); jQuery("#table").prop("usemap", 1);
equals( jQuery("#table").prop("useMap"), 1, "Check setting and retrieving useMap" ); equal( jQuery("#table").prop("useMap"), 1, "Check setting and retrieving useMap" );
jQuery("#table").prop("frameborder", 1); jQuery("#table").prop("frameborder", 1);
equals( jQuery("#table").prop("frameBorder"), 1, "Check setting and retrieving frameBorder" ); equal( jQuery("#table").prop("frameBorder"), 1, "Check setting and retrieving frameBorder" );
QUnit.reset(); QUnit.reset();
var body = document.body, var body = document.body,
...@@ -517,7 +517,7 @@ test("prop(String, Object)", function() { ...@@ -517,7 +517,7 @@ test("prop(String, Object)", function() {
ok( $body.prop("nextSibling") === null, "Make sure a null expando returns null" ); ok( $body.prop("nextSibling") === null, "Make sure a null expando returns null" );
body.foo = "bar"; body.foo = "bar";
equals( $body.prop("foo"), "bar", "Make sure the expando is preferred over the dom attribute" ); equal( $body.prop("foo"), "bar", "Make sure the expando is preferred over the dom attribute" );
body.foo = undefined; body.foo = undefined;
ok( $body.prop("foo") === undefined, "Make sure the expando is preferred over the dom attribute, even if undefined" ); ok( $body.prop("foo") === undefined, "Make sure the expando is preferred over the dom attribute, even if undefined" );
...@@ -525,8 +525,8 @@ test("prop(String, Object)", function() { ...@@ -525,8 +525,8 @@ test("prop(String, Object)", function() {
optgroup.appendChild( option ); optgroup.appendChild( option );
select.appendChild( optgroup ); select.appendChild( optgroup );
equals( jQuery(option).prop("selected"), true, "Make sure that a single option is selected, even when in an optgroup." ); equal( jQuery(option).prop("selected"), true, "Make sure that a single option is selected, even when in an optgroup." );
equals( jQuery(document).prop("nodeName"), "#document", "prop works correctly on document nodes (bug #7451)." ); equal( jQuery(document).prop("nodeName"), "#document", "prop works correctly on document nodes (bug #7451)." );
var attributeNode = document.createAttribute("irrelevant"), var attributeNode = document.createAttribute("irrelevant"),
commentNode = document.createComment("some comment"), commentNode = document.createComment("some comment"),
...@@ -574,55 +574,55 @@ test("prop('tabindex')", function() { ...@@ -574,55 +574,55 @@ test("prop('tabindex')", function() {
expect(8); expect(8);
// elements not natively tabbable // elements not natively tabbable
equals(jQuery("#listWithTabIndex").prop("tabindex"), 5, "not natively tabbable, with tabindex set to 0"); equal(jQuery("#listWithTabIndex").prop("tabindex"), 5, "not natively tabbable, with tabindex set to 0");
equals(jQuery("#divWithNoTabIndex").prop("tabindex"), undefined, "not natively tabbable, no tabindex set"); equal(jQuery("#divWithNoTabIndex").prop("tabindex"), undefined, "not natively tabbable, no tabindex set");
// anchor with href // anchor with href
equals(jQuery("#linkWithNoTabIndex").prop("tabindex"), 0, "anchor with href, no tabindex set"); equal(jQuery("#linkWithNoTabIndex").prop("tabindex"), 0, "anchor with href, no tabindex set");
equals(jQuery("#linkWithTabIndex").prop("tabindex"), 2, "anchor with href, tabindex set to 2"); equal(jQuery("#linkWithTabIndex").prop("tabindex"), 2, "anchor with href, tabindex set to 2");
equals(jQuery("#linkWithNegativeTabIndex").prop("tabindex"), -1, "anchor with href, tabindex set to -1"); equal(jQuery("#linkWithNegativeTabIndex").prop("tabindex"), -1, "anchor with href, tabindex set to -1");
// anchor without href // anchor without href
equals(jQuery("#linkWithNoHrefWithNoTabIndex").prop("tabindex"), undefined, "anchor without href, no tabindex set"); equal(jQuery("#linkWithNoHrefWithNoTabIndex").prop("tabindex"), undefined, "anchor without href, no tabindex set");
equals(jQuery("#linkWithNoHrefWithTabIndex").prop("tabindex"), 1, "anchor without href, tabindex set to 2"); equal(jQuery("#linkWithNoHrefWithTabIndex").prop("tabindex"), 1, "anchor without href, tabindex set to 2");
equals(jQuery("#linkWithNoHrefWithNegativeTabIndex").prop("tabindex"), -1, "anchor without href, no tabindex set"); equal(jQuery("#linkWithNoHrefWithNegativeTabIndex").prop("tabindex"), -1, "anchor without href, no tabindex set");
}); });
test("prop('tabindex', value)", function() { test("prop('tabindex', value)", function() {
expect(9); expect(9);
var element = jQuery("#divWithNoTabIndex"); var element = jQuery("#divWithNoTabIndex");
equals(element.prop("tabindex"), undefined, "start with no tabindex"); equal(element.prop("tabindex"), undefined, "start with no tabindex");
// set a positive string // set a positive string
element.prop("tabindex", "1"); element.prop("tabindex", "1");
equals(element.prop("tabindex"), 1, "set tabindex to 1 (string)"); equal(element.prop("tabindex"), 1, "set tabindex to 1 (string)");
// set a zero string // set a zero string
element.prop("tabindex", "0"); element.prop("tabindex", "0");
equals(element.prop("tabindex"), 0, "set tabindex to 0 (string)"); equal(element.prop("tabindex"), 0, "set tabindex to 0 (string)");
// set a negative string // set a negative string
element.prop("tabindex", "-1"); element.prop("tabindex", "-1");
equals(element.prop("tabindex"), -1, "set tabindex to -1 (string)"); equal(element.prop("tabindex"), -1, "set tabindex to -1 (string)");
// set a positive number // set a positive number
element.prop("tabindex", 1); element.prop("tabindex", 1);
equals(element.prop("tabindex"), 1, "set tabindex to 1 (number)"); equal(element.prop("tabindex"), 1, "set tabindex to 1 (number)");
// set a zero number // set a zero number
element.prop("tabindex", 0); element.prop("tabindex", 0);
equals(element.prop("tabindex"), 0, "set tabindex to 0 (number)"); equal(element.prop("tabindex"), 0, "set tabindex to 0 (number)");
// set a negative number // set a negative number
element.prop("tabindex", -1); element.prop("tabindex", -1);
equals(element.prop("tabindex"), -1, "set tabindex to -1 (number)"); equal(element.prop("tabindex"), -1, "set tabindex to -1 (number)");
element = jQuery("#linkWithTabIndex"); element = jQuery("#linkWithTabIndex");
equals(element.prop("tabindex"), 2, "start with tabindex 2"); equal(element.prop("tabindex"), 2, "start with tabindex 2");
element.prop("tabindex", -1); element.prop("tabindex", -1);
equals(element.prop("tabindex"), -1, "set negative tabindex"); equal(element.prop("tabindex"), -1, "set negative tabindex");
}); });
test("removeProp(String)", function() { test("removeProp(String)", function() {
...@@ -650,71 +650,71 @@ test("val()", function() { ...@@ -650,71 +650,71 @@ test("val()", function() {
expect(26); expect(26);
document.getElementById("text1").value = "bla"; document.getElementById("text1").value = "bla";
equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" ); equal( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
QUnit.reset(); QUnit.reset();
equals( jQuery("#text1").val(), "Test", "Check for value of input element" ); equal( jQuery("#text1").val(), "Test", "Check for value of input element" );
// ticket #1714 this caused a JS error in IE // ticket #1714 this caused a JS error in IE
equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" ); equal( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" ); ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
equals( jQuery("#select2").val(), "3", "Call val() on a single=\"single\" select" ); equal( jQuery("#select2").val(), "3", "Call val() on a single=\"single\" select" );
same( jQuery("#select3").val(), ["1", "2"], "Call val() on a multiple=\"multiple\" select" ); deepEqual( jQuery("#select3").val(), ["1", "2"], "Call val() on a multiple=\"multiple\" select" );
equals( jQuery("#option3c").val(), "2", "Call val() on a option element with value" ); equal( jQuery("#option3c").val(), "2", "Call val() on a option element with value" );
equals( jQuery("#option3a").val(), "", "Call val() on a option element with empty value" ); equal( jQuery("#option3a").val(), "", "Call val() on a option element with empty value" );
equals( jQuery("#option3e").val(), "no value", "Call val() on a option element with no value attribute" ); equal( jQuery("#option3e").val(), "no value", "Call val() on a option element with no value attribute" );
equals( jQuery("#option3a").val(), "", "Call val() on a option element with no value attribute" ); equal( jQuery("#option3a").val(), "", "Call val() on a option element with no value attribute" );
jQuery("#select3").val(""); jQuery("#select3").val("");
same( jQuery("#select3").val(), [""], "Call val() on a multiple=\"multiple\" select" ); deepEqual( jQuery("#select3").val(), [""], "Call val() on a multiple=\"multiple\" select" );
same( jQuery("#select4").val(), [], "Call val() on multiple=\"multiple\" select with all disabled options" ); deepEqual( jQuery("#select4").val(), [], "Call val() on multiple=\"multiple\" select with all disabled options" );
jQuery("#select4 optgroup").add("#select4 > [disabled]").attr("disabled", false); jQuery("#select4 optgroup").add("#select4 > [disabled]").attr("disabled", false);
same( jQuery("#select4").val(), ["2", "3"], "Call val() on multiple=\"multiple\" select with some disabled options" ); deepEqual( jQuery("#select4").val(), ["2", "3"], "Call val() on multiple=\"multiple\" select with some disabled options" );
jQuery("#select4").attr("disabled", true); jQuery("#select4").attr("disabled", true);
same( jQuery("#select4").val(), ["2", "3"], "Call val() on disabled multiple=\"multiple\" select" ); deepEqual( jQuery("#select4").val(), ["2", "3"], "Call val() on disabled multiple=\"multiple\" select" );
equals( jQuery("#select5").val(), "3", "Check value on ambiguous select." ); equal( jQuery("#select5").val(), "3", "Check value on ambiguous select." );
jQuery("#select5").val(1); jQuery("#select5").val(1);
equals( jQuery("#select5").val(), "1", "Check value on ambiguous select." ); equal( jQuery("#select5").val(), "1", "Check value on ambiguous select." );
jQuery("#select5").val(3); jQuery("#select5").val(3);
equals( jQuery("#select5").val(), "3", "Check value on ambiguous select." ); equal( jQuery("#select5").val(), "3", "Check value on ambiguous select." );
var checks = jQuery("<input type='checkbox' name='test' value='1'/><input type='checkbox' name='test' value='2'/><input type='checkbox' name='test' value=''/><input type='checkbox' name='test'/>").appendTo("#form"); var checks = jQuery("<input type='checkbox' name='test' value='1'/><input type='checkbox' name='test' value='2'/><input type='checkbox' name='test' value=''/><input type='checkbox' name='test'/>").appendTo("#form");
same( checks.serialize(), "", "Get unchecked values." ); deepEqual( checks.serialize(), "", "Get unchecked values." );
equals( checks.eq(3).val(), "on", "Make sure a value of 'on' is provided if none is specified." ); equal( checks.eq(3).val(), "on", "Make sure a value of 'on' is provided if none is specified." );
checks.val([ "2" ]); checks.val([ "2" ]);
same( checks.serialize(), "test=2", "Get a single checked value." ); deepEqual( checks.serialize(), "test=2", "Get a single checked value." );
checks.val([ "1", "" ]); checks.val([ "1", "" ]);
same( checks.serialize(), "test=1&test=", "Get multiple checked values." ); deepEqual( checks.serialize(), "test=1&test=", "Get multiple checked values." );
checks.val([ "", "2" ]); checks.val([ "", "2" ]);
same( checks.serialize(), "test=2&test=", "Get multiple checked values." ); deepEqual( checks.serialize(), "test=2&test=", "Get multiple checked values." );
checks.val([ "1", "on" ]); checks.val([ "1", "on" ]);
same( checks.serialize(), "test=1&test=on", "Get multiple checked values." ); deepEqual( checks.serialize(), "test=1&test=on", "Get multiple checked values." );
checks.remove(); checks.remove();
var $button = jQuery("<button value='foobar'>text</button>").insertAfter("#button"); var $button = jQuery("<button value='foobar'>text</button>").insertAfter("#button");
equals( $button.val(), "foobar", "Value retrieval on a button does not return innerHTML" ); equal( $button.val(), "foobar", "Value retrieval on a button does not return innerHTML" );
equals( $button.val("baz").html(), "text", "Setting the value does not change innerHTML" ); equal( $button.val("baz").html(), "text", "Setting the value does not change innerHTML" );
equals( jQuery("<option/>").val("test").attr("value"), "test", "Setting value sets the value attribute" ); equal( jQuery("<option/>").val("test").attr("value"), "test", "Setting value sets the value attribute" );
}); });
if ( "value" in document.createElement("meter") && if ( "value" in document.createElement("meter") &&
...@@ -746,32 +746,32 @@ var testVal = function(valueObj) { ...@@ -746,32 +746,32 @@ var testVal = function(valueObj) {
QUnit.reset(); QUnit.reset();
jQuery("#text1").val(valueObj( "test" )); jQuery("#text1").val(valueObj( "test" ));
equals( document.getElementById("text1").value, "test", "Check for modified (via val(String)) value of input element" ); equal( document.getElementById("text1").value, "test", "Check for modified (via val(String)) value of input element" );
jQuery("#text1").val(valueObj( undefined )); jQuery("#text1").val(valueObj( undefined ));
equals( document.getElementById("text1").value, "", "Check for modified (via val(undefined)) value of input element" ); equal( document.getElementById("text1").value, "", "Check for modified (via val(undefined)) value of input element" );
jQuery("#text1").val(valueObj( 67 )); jQuery("#text1").val(valueObj( 67 ));
equals( document.getElementById("text1").value, "67", "Check for modified (via val(Number)) value of input element" ); equal( document.getElementById("text1").value, "67", "Check for modified (via val(Number)) value of input element" );
jQuery("#text1").val(valueObj( null )); jQuery("#text1").val(valueObj( null ));
equals( document.getElementById("text1").value, "", "Check for modified (via val(null)) value of input element" ); equal( document.getElementById("text1").value, "", "Check for modified (via val(null)) value of input element" );
var $select1 = jQuery("#select1"); var $select1 = jQuery("#select1");
$select1.val(valueObj( "3" )); $select1.val(valueObj( "3" ));
equals( $select1.val(), "3", "Check for modified (via val(String)) value of select element" ); equal( $select1.val(), "3", "Check for modified (via val(String)) value of select element" );
$select1.val(valueObj( 2 )); $select1.val(valueObj( 2 ));
equals( $select1.val(), "2", "Check for modified (via val(Number)) value of select element" ); equal( $select1.val(), "2", "Check for modified (via val(Number)) value of select element" );
$select1.append("<option value='4'>four</option>"); $select1.append("<option value='4'>four</option>");
$select1.val(valueObj( 4 )); $select1.val(valueObj( 4 ));
equals( $select1.val(), "4", "Should be possible to set the val() to a newly created option" ); equal( $select1.val(), "4", "Should be possible to set the val() to a newly created option" );
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents(); var j = jQuery("#nonnodes").contents();
j.val(valueObj( "asdf" )); j.val(valueObj( "asdf" ));
equals( 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");
} }
...@@ -802,49 +802,49 @@ test("val(Function) with incoming value", function() { ...@@ -802,49 +802,49 @@ test("val(Function) with incoming value", function() {
var oldVal = jQuery("#text1").val(); var oldVal = jQuery("#text1").val();
jQuery("#text1").val(function(i, val) { jQuery("#text1").val(function(i, val) {
equals( val, oldVal, "Make sure the incoming value is correct." ); equal( val, oldVal, "Make sure the incoming value is correct." );
return "test"; return "test";
}); });
equals( document.getElementById("text1").value, "test", "Check for modified (via val(String)) value of input element" ); equal( document.getElementById("text1").value, "test", "Check for modified (via val(String)) value of input element" );
oldVal = jQuery("#text1").val(); oldVal = jQuery("#text1").val();
jQuery("#text1").val(function(i, val) { jQuery("#text1").val(function(i, val) {
equals( val, oldVal, "Make sure the incoming value is correct." ); equal( val, oldVal, "Make sure the incoming value is correct." );
return 67; return 67;
}); });
equals( document.getElementById("text1").value, "67", "Check for modified (via val(Number)) value of input element" ); equal( document.getElementById("text1").value, "67", "Check for modified (via val(Number)) value of input element" );
oldVal = jQuery("#select1").val(); oldVal = jQuery("#select1").val();
jQuery("#select1").val(function(i, val) { jQuery("#select1").val(function(i, val) {
equals( val, oldVal, "Make sure the incoming value is correct." ); equal( val, oldVal, "Make sure the incoming value is correct." );
return "3"; return "3";
}); });
equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" ); equal( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
oldVal = jQuery("#select1").val(); oldVal = jQuery("#select1").val();
jQuery("#select1").val(function(i, val) { jQuery("#select1").val(function(i, val) {
equals( val, oldVal, "Make sure the incoming value is correct." ); equal( val, oldVal, "Make sure the incoming value is correct." );
return 2; return 2;
}); });
equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" ); equal( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
jQuery("#select1").append("<option value='4'>four</option>"); jQuery("#select1").append("<option value='4'>four</option>");
oldVal = jQuery("#select1").val(); oldVal = jQuery("#select1").val();
jQuery("#select1").val(function(i, val) { jQuery("#select1").val(function(i, val) {
equals( val, oldVal, "Make sure the incoming value is correct." ); equal( val, oldVal, "Make sure the incoming value is correct." );
return 4; return 4;
}); });
equals( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" ); equal( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" );
}); });
// testing if a form.reset() breaks a subsequent call to a select element's .val() (in IE only) // testing if a form.reset() breaks a subsequent call to a select element's .val() (in IE only)
...@@ -861,7 +861,7 @@ test("val(select) after form.reset() (Bug #2551)", function() { ...@@ -861,7 +861,7 @@ test("val(select) after form.reset() (Bug #2551)", function() {
equal( jQuery("#kkk").val(), "cf", "Check value of select after form reset." ); equal( jQuery("#kkk").val(), "cf", "Check value of select after form reset." );
// re-verify the multi-select is not broken (after form.reset) by our fix for single-select // re-verify the multi-select is not broken (after form.reset) by our fix for single-select
same( jQuery("#select3").val(), ["1", "2"], "Call val() on a multiple=\"multiple\" select" ); deepEqual( jQuery("#select3").val(), ["1", "2"], "Call val() on a multiple=\"multiple\" select" );
jQuery("#kk").remove(); jQuery("#kk").remove();
}); });
...@@ -887,15 +887,15 @@ var testAddClass = function(valueObj) { ...@@ -887,15 +887,15 @@ var testAddClass = function(valueObj) {
div = jQuery("<div/>"); div = jQuery("<div/>");
div.addClass( valueObj("test") ); div.addClass( valueObj("test") );
equals( div.attr("class"), "test", "Make sure there's no extra whitespace." ); equal( div.attr("class"), "test", "Make sure there's no extra whitespace." );
div.attr("class", " foo"); div.attr("class", " foo");
div.addClass( valueObj("test") ); div.addClass( valueObj("test") );
equals( div.attr("class"), "foo test", "Make sure there's no extra whitespace." ); equal( div.attr("class"), "foo test", "Make sure there's no extra whitespace." );
div.attr("class", "foo"); div.attr("class", "foo");
div.addClass( valueObj("bar baz") ); div.addClass( valueObj("bar baz") );
equals( div.attr("class"), "foo bar baz", "Make sure there isn't too much trimming." ); equal( div.attr("class"), "foo bar baz", "Make sure there isn't too much trimming." );
div.removeClass(); div.removeClass();
div.addClass( valueObj("foo") ).addClass( valueObj("foo") ); div.addClass( valueObj("foo") ).addClass( valueObj("foo") );
...@@ -927,7 +927,7 @@ test("addClass(Function) with incoming value", function() { ...@@ -927,7 +927,7 @@ test("addClass(Function) with incoming value", function() {
div.addClass(function(i, val) { div.addClass(function(i, val) {
if ( this.id !== "_firebugConsole") { if ( this.id !== "_firebugConsole") {
equals( val, old[i], "Make sure the incoming value is correct." ); equal( val, old[i], "Make sure the incoming value is correct." );
return "test"; return "test";
} }
}); });
...@@ -975,12 +975,12 @@ var testRemoveClass = function(valueObj) { ...@@ -975,12 +975,12 @@ var testRemoveClass = function(valueObj) {
div.className = " test foo "; div.className = " test foo ";
jQuery(div).removeClass( valueObj("foo") ); jQuery(div).removeClass( valueObj("foo") );
equals( div.className, "test", "Make sure remaining className is trimmed." ); equal( div.className, "test", "Make sure remaining className is trimmed." );
div.className = " test "; div.className = " test ";
jQuery(div).removeClass( valueObj("test") ); jQuery(div).removeClass( valueObj("test") );
equals( div.className, "", "Make sure there is nothing left after everything is removed." ); equal( div.className, "", "Make sure there is nothing left after everything is removed." );
}; };
test("removeClass(String) - simple", function() { test("removeClass(String) - simple", function() {
...@@ -1000,7 +1000,7 @@ test("removeClass(Function) with incoming value", function() { ...@@ -1000,7 +1000,7 @@ test("removeClass(Function) with incoming value", function() {
$divs.removeClass(function(i, val) { $divs.removeClass(function(i, val) {
if ( this.id !== "_firebugConsole" ) { if ( this.id !== "_firebugConsole" ) {
equals( val, old[i], "Make sure the incoming value is correct." ); equal( val, old[i], "Make sure the incoming value is correct." );
return "test"; return "test";
} }
}); });
...@@ -1127,17 +1127,17 @@ test("addClass, removeClass, hasClass", function() { ...@@ -1127,17 +1127,17 @@ test("addClass, removeClass, hasClass", function() {
var jq = jQuery("<p>Hi</p>"), x = jq[0]; var jq = jQuery("<p>Hi</p>"), x = jq[0];
jq.addClass("hi"); jq.addClass("hi");
equals( x.className, "hi", "Check single added class" ); equal( x.className, "hi", "Check single added class" );
jq.addClass("foo bar"); jq.addClass("foo bar");
equals( x.className, "hi foo bar", "Check more added classes" ); equal( x.className, "hi foo bar", "Check more added classes" );
jq.removeClass(); jq.removeClass();
equals( x.className, "", "Remove all classes" ); equal( x.className, "", "Remove all classes" );
jq.addClass("hi foo bar"); jq.addClass("hi foo bar");
jq.removeClass("foo"); jq.removeClass("foo");
equals( x.className, "hi bar", "Check removal of one class" ); equal( x.className, "hi bar", "Check removal of one class" );
ok( jq.hasClass("hi"), "Check has1" ); ok( jq.hasClass("hi"), "Check has1" );
ok( jq.hasClass("bar"), "Check has2" ); ok( jq.hasClass("bar"), "Check has2" );
......
...@@ -69,7 +69,7 @@ jQuery.each( tests, function( flags, resultString ) { ...@@ -69,7 +69,7 @@ jQuery.each( tests, function( flags, resultString ) {
output = "X"; output = "X";
cblist = jQuery.Callbacks( flags ); cblist = jQuery.Callbacks( flags );
cblist.add(function() { cblist.add(function() {
equals( this, window, "Basic binding and firing (context)" ); equal( this, window, "Basic binding and firing (context)" );
output += Array.prototype.join.call( arguments, "" ); output += Array.prototype.join.call( arguments, "" );
}); });
cblist.fireWith( window, [ "A", "B" ] ); cblist.fireWith( window, [ "A", "B" ] );
...@@ -79,7 +79,7 @@ jQuery.each( tests, function( flags, resultString ) { ...@@ -79,7 +79,7 @@ jQuery.each( tests, function( flags, resultString ) {
output = ""; output = "";
cblist = jQuery.Callbacks( flags ); cblist = jQuery.Callbacks( flags );
cblist.add(function() { cblist.add(function() {
equals( this, window, "fireWith with no arguments (context is window)" ); equal( this, window, "fireWith with no arguments (context is window)" );
strictEqual( arguments.length, 0, "fireWith with no arguments (no arguments)" ); strictEqual( arguments.length, 0, "fireWith with no arguments (no arguments)" );
}); });
cblist.fireWith(); cblist.fireWith();
......
...@@ -16,21 +16,21 @@ test("jQuery()", function() { ...@@ -16,21 +16,21 @@ test("jQuery()", function() {
// Basic constructor's behavior // Basic constructor's behavior
equals( jQuery().length, 0, "jQuery() === jQuery([])" ); equal( jQuery().length, 0, "jQuery() === jQuery([])" );
equals( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" ); equal( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" );
equals( jQuery(null).length, 0, "jQuery(null) === jQuery([])" ); equal( jQuery(null).length, 0, "jQuery(null) === jQuery([])" );
equals( jQuery("").length, 0, "jQuery('') === jQuery([])" ); equal( jQuery("").length, 0, "jQuery('') === jQuery([])" );
equals( jQuery("#").length, 0, "jQuery('#') === jQuery([])" ); equal( jQuery("#").length, 0, "jQuery('#') === jQuery([])" );
var obj = jQuery("div"); var obj = jQuery("div");
equals( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" ); equal( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" );
// can actually yield more than one, when iframes are included, the window is an array as well // can actually yield more than one, when iframes are included, the window is an array as well
equals( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" ); equal( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" );
var main = jQuery("#qunit-fixture"); var main = jQuery("#qunit-fixture");
same( jQuery("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); deepEqual( jQuery("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
/* /*
// disabled since this test was doing nothing. i tried to fix it but i'm not sure // disabled since this test was doing nothing. i tried to fix it but i'm not sure
...@@ -38,7 +38,7 @@ test("jQuery()", function() { ...@@ -38,7 +38,7 @@ test("jQuery()", function() {
// make sure this is handled // make sure this is handled
var crlfContainer = jQuery('<p>\r\n</p>'); var crlfContainer = jQuery('<p>\r\n</p>');
var x = crlfContainer.contents().get(0).nodeValue; var x = crlfContainer.contents().get(0).nodeValue;
equals( x, what???, "Check for \\r and \\n in jQuery()" ); equal( x, what???, "Check for \\r and \\n in jQuery()" );
*/ */
/* // Disabled until we add this functionality in /* // Disabled until we add this functionality in
...@@ -51,18 +51,18 @@ test("jQuery()", function() { ...@@ -51,18 +51,18 @@ test("jQuery()", function() {
ok( pass, "jQuery('&lt;tag&gt;') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/ ok( pass, "jQuery('&lt;tag&gt;') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/
var code = jQuery("<code/>"); var code = jQuery("<code/>");
equals( code.length, 1, "Correct number of elements generated for code" ); equal( code.length, 1, "Correct number of elements generated for code" );
equals( code.parent().length, 0, "Make sure that the generated HTML has no parent." ); equal( code.parent().length, 0, "Make sure that the generated HTML has no parent." );
var img = jQuery("<img/>"); var img = jQuery("<img/>");
equals( img.length, 1, "Correct number of elements generated for img" ); equal( img.length, 1, "Correct number of elements generated for img" );
equals( img.parent().length, 0, "Make sure that the generated HTML has no parent." ); equal( img.parent().length, 0, "Make sure that the generated HTML has no parent." );
var div = jQuery("<div/><hr/><code/><b/>"); var div = jQuery("<div/><hr/><code/><b/>");
equals( div.length, 4, "Correct number of elements generated for div hr code b" ); equal( div.length, 4, "Correct number of elements generated for div hr code b" );
equals( div.parent().length, 0, "Make sure that the generated HTML has no parent." ); equal( div.parent().length, 0, "Make sure that the generated HTML has no parent." );
equals( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" ); equal( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" );
equals( jQuery(document.body).get(0), jQuery("body").get(0), "Test passing an html node to the factory" ); equal( jQuery(document.body).get(0), jQuery("body").get(0), "Test passing an html node to the factory" );
var exec = false; var exec = false;
...@@ -75,13 +75,13 @@ test("jQuery()", function() { ...@@ -75,13 +75,13 @@ test("jQuery()", function() {
id: "test3" id: "test3"
}); });
equals( elem[0].style.width, "10px", "jQuery() quick setter width"); equal( elem[0].style.width, "10px", "jQuery() quick setter width");
equals( elem[0].style.paddingLeft, "1px", "jQuery quick setter css"); equal( elem[0].style.paddingLeft, "1px", "jQuery quick setter css");
equals( elem[0].style.paddingRight, "1px", "jQuery quick setter css"); equal( elem[0].style.paddingRight, "1px", "jQuery quick setter css");
equals( elem[0].childNodes.length, 1, "jQuery quick setter text"); equal( elem[0].childNodes.length, 1, "jQuery quick setter text");
equals( elem[0].firstChild.nodeValue, "test", "jQuery quick setter text"); equal( elem[0].firstChild.nodeValue, "test", "jQuery quick setter text");
equals( elem[0].className, "test2", "jQuery() quick setter class"); equal( elem[0].className, "test2", "jQuery() quick setter class");
equals( elem[0].id, "test3", "jQuery() quick setter id"); equal( elem[0].id, "test3", "jQuery() quick setter id");
exec = true; exec = true;
elem.click(); elem.click();
...@@ -92,21 +92,21 @@ test("jQuery()", function() { ...@@ -92,21 +92,21 @@ test("jQuery()", function() {
for ( var i = 0; i < 3; ++i ) { for ( var i = 0; i < 3; ++i ) {
elem = jQuery("<input type='text' value='TEST' />"); elem = jQuery("<input type='text' value='TEST' />");
} }
equals( elem[0].defaultValue, "TEST", "Ensure cached nodes are cloned properly (Bug #6655)" ); equal( elem[0].defaultValue, "TEST", "Ensure cached nodes are cloned properly (Bug #6655)" );
// manually clean up detached elements // manually clean up detached elements
elem.remove(); elem.remove();
equals( jQuery(" <div/> ").length, 1, "Make sure whitespace is trimmed." ); equal( jQuery(" <div/> ").length, 1, "Make sure whitespace is trimmed." );
equals( jQuery(" a<div/>b ").length, 1, "Make sure whitespace and other characters are trimmed." ); equal( jQuery(" a<div/>b ").length, 1, "Make sure whitespace and other characters are trimmed." );
var long = ""; var long = "";
for ( var i = 0; i < 128; i++ ) { for ( var i = 0; i < 128; i++ ) {
long += "12345678"; long += "12345678";
} }
equals( jQuery(" <div>" + long + "</div> ").length, 1, "Make sure whitespace is trimmed on long strings." ); equal( jQuery(" <div>" + long + "</div> ").length, 1, "Make sure whitespace is trimmed on long strings." );
equals( jQuery(" a<div>" + long + "</div>b ").length, 1, "Make sure whitespace and other characters are trimmed on long strings." ); equal( jQuery(" a<div>" + long + "</div>b ").length, 1, "Make sure whitespace and other characters are trimmed on long strings." );
}); });
test("selector state", function() { test("selector state", function() {
...@@ -115,68 +115,68 @@ test("selector state", function() { ...@@ -115,68 +115,68 @@ test("selector state", function() {
var test; var test;
test = jQuery(undefined); test = jQuery(undefined);
equals( test.selector, "", "Empty jQuery Selector" ); equal( test.selector, "", "Empty jQuery Selector" );
equals( test.context, undefined, "Empty jQuery Context" ); equal( test.context, undefined, "Empty jQuery Context" );
test = jQuery(document); test = jQuery(document);
equals( test.selector, "", "Document Selector" ); equal( test.selector, "", "Document Selector" );
equals( test.context, document, "Document Context" ); equal( test.context, document, "Document Context" );
test = jQuery(document.body); test = jQuery(document.body);
equals( test.selector, "", "Body Selector" ); equal( test.selector, "", "Body Selector" );
equals( test.context, document.body, "Body Context" ); equal( test.context, document.body, "Body Context" );
test = jQuery("#qunit-fixture"); test = jQuery("#qunit-fixture");
equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
equals( test.context, document, "#qunit-fixture Context" ); equal( test.context, document, "#qunit-fixture Context" );
test = jQuery("#notfoundnono"); test = jQuery("#notfoundnono");
equals( test.selector, "#notfoundnono", "#notfoundnono Selector" ); equal( test.selector, "#notfoundnono", "#notfoundnono Selector" );
equals( test.context, document, "#notfoundnono Context" ); equal( test.context, document, "#notfoundnono Context" );
test = jQuery("#qunit-fixture", document); test = jQuery("#qunit-fixture", document);
equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
equals( test.context, document, "#qunit-fixture Context" ); equal( test.context, document, "#qunit-fixture Context" );
test = jQuery("#qunit-fixture", document.body); test = jQuery("#qunit-fixture", document.body);
equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
equals( test.context, document.body, "#qunit-fixture Context" ); equal( test.context, document.body, "#qunit-fixture Context" );
// Test cloning // Test cloning
test = jQuery(test); test = jQuery(test);
equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
equals( test.context, document.body, "#qunit-fixture Context" ); equal( test.context, document.body, "#qunit-fixture Context" );
test = jQuery(document.body).find("#qunit-fixture"); test = jQuery(document.body).find("#qunit-fixture");
equals( test.selector, "#qunit-fixture", "#qunit-fixture find Selector" ); equal( test.selector, "#qunit-fixture", "#qunit-fixture find Selector" );
equals( test.context, document.body, "#qunit-fixture find Context" ); equal( test.context, document.body, "#qunit-fixture find Context" );
test = jQuery("#qunit-fixture").filter("div"); test = jQuery("#qunit-fixture").filter("div");
equals( test.selector, "#qunit-fixture.filter(div)", "#qunit-fixture filter Selector" ); equal( test.selector, "#qunit-fixture.filter(div)", "#qunit-fixture filter Selector" );
equals( test.context, document, "#qunit-fixture filter Context" ); equal( test.context, document, "#qunit-fixture filter Context" );
test = jQuery("#qunit-fixture").not("div"); test = jQuery("#qunit-fixture").not("div");
equals( test.selector, "#qunit-fixture.not(div)", "#qunit-fixture not Selector" ); equal( test.selector, "#qunit-fixture.not(div)", "#qunit-fixture not Selector" );
equals( test.context, document, "#qunit-fixture not Context" ); equal( test.context, document, "#qunit-fixture not Context" );
test = jQuery("#qunit-fixture").filter("div").not("div"); test = jQuery("#qunit-fixture").filter("div").not("div");
equals( test.selector, "#qunit-fixture.filter(div).not(div)", "#qunit-fixture filter, not Selector" ); equal( test.selector, "#qunit-fixture.filter(div).not(div)", "#qunit-fixture filter, not Selector" );
equals( test.context, document, "#qunit-fixture filter, not Context" ); equal( test.context, document, "#qunit-fixture filter, not Context" );
test = jQuery("#qunit-fixture").filter("div").not("div").end(); test = jQuery("#qunit-fixture").filter("div").not("div").end();
equals( test.selector, "#qunit-fixture.filter(div)", "#qunit-fixture filter, not, end Selector" ); equal( test.selector, "#qunit-fixture.filter(div)", "#qunit-fixture filter, not, end Selector" );
equals( test.context, document, "#qunit-fixture filter, not, end Context" ); equal( test.context, document, "#qunit-fixture filter, not, end Context" );
test = jQuery("#qunit-fixture").parent("body"); test = jQuery("#qunit-fixture").parent("body");
equals( test.selector, "#qunit-fixture.parent(body)", "#qunit-fixture parent Selector" ); equal( test.selector, "#qunit-fixture.parent(body)", "#qunit-fixture parent Selector" );
equals( test.context, document, "#qunit-fixture parent Context" ); equal( test.context, document, "#qunit-fixture parent Context" );
test = jQuery("#qunit-fixture").eq(0); test = jQuery("#qunit-fixture").eq(0);
equals( test.selector, "#qunit-fixture.slice(0,1)", "#qunit-fixture eq Selector" ); equal( test.selector, "#qunit-fixture.slice(0,1)", "#qunit-fixture eq Selector" );
equals( test.context, document, "#qunit-fixture eq Context" ); equal( test.context, document, "#qunit-fixture eq Context" );
var d = "<div />"; var d = "<div />";
equals( equal(
jQuery(d).appendTo(jQuery(d)).selector, jQuery(d).appendTo(jQuery(d)).selector,
jQuery(d).appendTo(d).selector, jQuery(d).appendTo(d).selector,
"manipulation methods make same selector for jQuery objects" "manipulation methods make same selector for jQuery objects"
...@@ -215,8 +215,8 @@ test("browser", function() { ...@@ -215,8 +215,8 @@ test("browser", function() {
var parts = this.split("\t"); var parts = this.split("\t");
if ( parts[2] ) { if ( parts[2] ) {
var ua = jQuery.uaMatch( parts[2] ); var ua = jQuery.uaMatch( parts[2] );
equals( ua.browser, parts[0], "Checking browser for " + parts[2] ); equal( ua.browser, parts[0], "Checking browser for " + parts[2] );
equals( ua.version, parts[1], "Checking version string for " + parts[2] ); equal( ua.version, parts[1], "Checking version string for " + parts[2] );
} }
}); });
...@@ -228,7 +228,7 @@ test("browser", function() { ...@@ -228,7 +228,7 @@ test("browser", function() {
test("amdModule", function() { test("amdModule", function() {
expect(1); expect(1);
equals( jQuery, amdDefined, "Make sure defined module matches jQuery" ); equal( jQuery, amdDefined, "Make sure defined module matches jQuery" );
}); });
test("noConflict", function() { test("noConflict", function() {
...@@ -236,15 +236,15 @@ test("noConflict", function() { ...@@ -236,15 +236,15 @@ test("noConflict", function() {
var $$ = jQuery; var $$ = jQuery;
equals( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" ); equal( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" );
equals( jQuery, $$, "Make sure jQuery wasn't touched." ); equal( jQuery, $$, "Make sure jQuery wasn't touched." );
equals( $, original$, "Make sure $ was reverted." ); equal( $, original$, "Make sure $ was reverted." );
jQuery = $ = $$; jQuery = $ = $$;
equals( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" ); equal( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" );
equals( jQuery, originaljQuery, "Make sure jQuery was reverted." ); equal( jQuery, originaljQuery, "Make sure jQuery was reverted." );
equals( $, original$, "Make sure $ was reverted." ); equal( $, original$, "Make sure $ was reverted." );
ok( $$("#qunit-fixture").html("test"), "Make sure that jQuery still works." ); ok( $$("#qunit-fixture").html("test"), "Make sure that jQuery still works." );
jQuery = $$; jQuery = $$;
...@@ -255,44 +255,44 @@ test("trim", function() { ...@@ -255,44 +255,44 @@ test("trim", function() {
var nbsp = String.fromCharCode(160); var nbsp = String.fromCharCode(160);
equals( jQuery.trim("hello "), "hello", "trailing space" ); equal( jQuery.trim("hello "), "hello", "trailing space" );
equals( jQuery.trim(" hello"), "hello", "leading space" ); equal( jQuery.trim(" hello"), "hello", "leading space" );
equals( jQuery.trim(" hello "), "hello", "space on both sides" ); equal( jQuery.trim(" hello "), "hello", "space on both sides" );
equals( jQuery.trim(" " + nbsp + "hello " + nbsp + " "), "hello", "&nbsp;" ); equal( jQuery.trim(" " + nbsp + "hello " + nbsp + " "), "hello", "&nbsp;" );
equals( jQuery.trim(), "", "Nothing in." ); equal( jQuery.trim(), "", "Nothing in." );
equals( jQuery.trim( undefined ), "", "Undefined" ); equal( jQuery.trim( undefined ), "", "Undefined" );
equals( jQuery.trim( null ), "", "Null" ); equal( jQuery.trim( null ), "", "Null" );
equals( jQuery.trim( 5 ), "5", "Number" ); equal( jQuery.trim( 5 ), "5", "Number" );
equals( jQuery.trim( false ), "false", "Boolean" ); equal( jQuery.trim( false ), "false", "Boolean" );
}); });
test("type", function() { test("type", function() {
expect(23); expect(23);
equals( jQuery.type(null), "null", "null" ); equal( jQuery.type(null), "null", "null" );
equals( jQuery.type(undefined), "undefined", "undefined" ); equal( jQuery.type(undefined), "undefined", "undefined" );
equals( jQuery.type(true), "boolean", "Boolean" ); equal( jQuery.type(true), "boolean", "Boolean" );
equals( jQuery.type(false), "boolean", "Boolean" ); equal( jQuery.type(false), "boolean", "Boolean" );
equals( jQuery.type(Boolean(true)), "boolean", "Boolean" ); equal( jQuery.type(Boolean(true)), "boolean", "Boolean" );
equals( jQuery.type(0), "number", "Number" ); equal( jQuery.type(0), "number", "Number" );
equals( jQuery.type(1), "number", "Number" ); equal( jQuery.type(1), "number", "Number" );
equals( jQuery.type(Number(1)), "number", "Number" ); equal( jQuery.type(Number(1)), "number", "Number" );
equals( jQuery.type(""), "string", "String" ); equal( jQuery.type(""), "string", "String" );
equals( jQuery.type("a"), "string", "String" ); equal( jQuery.type("a"), "string", "String" );
equals( jQuery.type(String("a")), "string", "String" ); equal( jQuery.type(String("a")), "string", "String" );
equals( jQuery.type({}), "object", "Object" ); equal( jQuery.type({}), "object", "Object" );
equals( jQuery.type(/foo/), "regexp", "RegExp" ); equal( jQuery.type(/foo/), "regexp", "RegExp" );
equals( jQuery.type(new RegExp("asdf")), "regexp", "RegExp" ); equal( jQuery.type(new RegExp("asdf")), "regexp", "RegExp" );
equals( jQuery.type([1]), "array", "Array" ); equal( jQuery.type([1]), "array", "Array" );
equals( jQuery.type(new Date()), "date", "Date" ); equal( jQuery.type(new Date()), "date", "Date" );
equals( jQuery.type(new Function("return;")), "function", "Function" ); equal( jQuery.type(new Function("return;")), "function", "Function" );
equals( jQuery.type(function(){}), "function", "Function" ); equal( jQuery.type(function(){}), "function", "Function" );
equals( jQuery.type(window), "object", "Window" ); equal( jQuery.type(window), "object", "Window" );
equals( jQuery.type(document), "object", "Document" ); equal( jQuery.type(document), "object", "Document" );
equals( jQuery.type(document.body), "object", "Element" ); equal( jQuery.type(document.body), "object", "Element" );
equals( jQuery.type(document.createTextNode("foo")), "object", "TextNode" ); equal( jQuery.type(document.createTextNode("foo")), "object", "TextNode" );
equals( jQuery.type(document.getElementsByTagName("*")), "object", "NodeList" ); equal( jQuery.type(document.getElementsByTagName("*")), "object", "NodeList" );
}); });
test("isPlainObject", function() { test("isPlainObject", function() {
...@@ -475,23 +475,23 @@ test( "isNumeric", function() { ...@@ -475,23 +475,23 @@ test( "isNumeric", function() {
ok( t(3.1415), "Positive floating point number"); ok( t(3.1415), "Positive floating point number");
ok( t(8e5), "Exponential notation"); ok( t(8e5), "Exponential notation");
ok( t("123e-2"), "Exponential notation string"); ok( t("123e-2"), "Exponential notation string");
equals( t(""), false, "Empty string"); equal( t(""), false, "Empty string");
equals( t(" "), false, "Whitespace characters string"); equal( t(" "), false, "Whitespace characters string");
equals( t("\t\t"), false, "Tab characters string"); equal( t("\t\t"), false, "Tab characters string");
equals( t("abcdefghijklm1234567890"), false, "Alphanumeric character string"); equal( t("abcdefghijklm1234567890"), false, "Alphanumeric character string");
equals( t("xabcdefx"), false, "Non-numeric character string"); equal( t("xabcdefx"), false, "Non-numeric character string");
equals( t(true), false, "Boolean true literal"); equal( t(true), false, "Boolean true literal");
equals( t(false), false, "Boolean false literal"); equal( t(false), false, "Boolean false literal");
equals( t("bcfed5.2"), false, "Number with preceding non-numeric characters"); equal( t("bcfed5.2"), false, "Number with preceding non-numeric characters");
equals( t("7.2acdgs"), false, "Number with trailling non-numeric characters"); equal( t("7.2acdgs"), false, "Number with trailling non-numeric characters");
equals( t(undefined), false, "Undefined value"); equal( t(undefined), false, "Undefined value");
equals( t(null), false, "Null value"); equal( t(null), false, "Null value");
equals( t(NaN), false, "NaN value"); equal( t(NaN), false, "NaN value");
equals( t(Infinity), false, "Infinity primitive"); equal( t(Infinity), false, "Infinity primitive");
equals( t(Number.POSITIVE_INFINITY), false, "Positive Infinity"); equal( t(Number.POSITIVE_INFINITY), false, "Positive Infinity");
equals( t(Number.NEGATIVE_INFINITY), false, "Negative Infinity"); equal( t(Number.NEGATIVE_INFINITY), false, "Negative Infinity");
equals( t({}), false, "Empty object"); equal( t({}), false, "Empty object");
equals( t(function(){} ), false, "Instance of a function"); equal( t(function(){} ), false, "Instance of a function");
}); });
test("isXMLDoc - HTML", function() { test("isXMLDoc - HTML", function() {
...@@ -583,11 +583,11 @@ test("jQuery('html')", function() { ...@@ -583,11 +583,11 @@ test("jQuery('html')", function() {
// Test multi-line HTML // Test multi-line HTML
var div = jQuery("<div>\r\nsome text\n<p>some p</p>\nmore text\r\n</div>")[0]; var div = jQuery("<div>\r\nsome text\n<p>some p</p>\nmore text\r\n</div>")[0];
equals( div.nodeName.toUpperCase(), "DIV", "Make sure we're getting a div." ); equal( div.nodeName.toUpperCase(), "DIV", "Make sure we're getting a div." );
equals( div.firstChild.nodeType, 3, "Text node." ); equal( div.firstChild.nodeType, 3, "Text node." );
equals( div.lastChild.nodeType, 3, "Text node." ); equal( div.lastChild.nodeType, 3, "Text node." );
equals( div.childNodes[1].nodeType, 1, "Paragraph." ); equal( div.childNodes[1].nodeType, 1, "Paragraph." );
equals( div.childNodes[1].firstChild.nodeType, 3, "Paragraph text." ); equal( div.childNodes[1].firstChild.nodeType, 3, "Paragraph text." );
QUnit.reset(); QUnit.reset();
ok( jQuery("<link rel='stylesheet'/>")[0], "Creating a link" ); ok( jQuery("<link rel='stylesheet'/>")[0], "Creating a link" );
...@@ -613,9 +613,9 @@ test("jQuery('html')", function() { ...@@ -613,9 +613,9 @@ test("jQuery('html')", function() {
} }
html.push("</ul>"); html.push("</ul>");
html = jQuery(html.join(""))[0]; html = jQuery(html.join(""))[0];
equals( html.nodeName.toUpperCase(), "UL"); equal( html.nodeName.toUpperCase(), "UL");
equals( html.firstChild.nodeName.toUpperCase(), "LI"); equal( html.firstChild.nodeName.toUpperCase(), "LI");
equals( html.childNodes.length, 50000 ); equal( html.childNodes.length, 50000 );
}); });
test("jQuery('html', context)", function() { test("jQuery('html', context)", function() {
...@@ -623,7 +623,7 @@ test("jQuery('html', context)", function() { ...@@ -623,7 +623,7 @@ test("jQuery('html', context)", function() {
var $div = jQuery("<div/>")[0]; var $div = jQuery("<div/>")[0];
var $span = jQuery("<span/>", $div); var $span = jQuery("<span/>", $div);
equals($span.length, 1, "Verify a span created with a div context works, #1763"); equal($span.length, 1, "Verify a span created with a div context works, #1763");
}); });
if ( !isLocal ) { if ( !isLocal ) {
...@@ -633,9 +633,9 @@ test("jQuery(selector, xml).text(str) - Loaded via XML document", function() { ...@@ -633,9 +633,9 @@ test("jQuery(selector, xml).text(str) - Loaded via XML document", function() {
jQuery.get("data/dashboard.xml", function(xml) { jQuery.get("data/dashboard.xml", function(xml) {
// tests for #1419 where IE was a problem // tests for #1419 where IE was a problem
var tab = jQuery("tab", xml).eq(0); var tab = jQuery("tab", xml).eq(0);
equals( tab.text(), "blabla", "Verify initial text correct" ); equal( tab.text(), "blabla", "Verify initial text correct" );
tab.text("newtext"); tab.text("newtext");
equals( tab.text(), "newtext", "Verify new text correct" ); equal( tab.text(), "newtext", "Verify new text correct" );
start(); start();
}); });
}); });
...@@ -643,32 +643,32 @@ test("jQuery(selector, xml).text(str) - Loaded via XML document", function() { ...@@ -643,32 +643,32 @@ test("jQuery(selector, xml).text(str) - Loaded via XML document", function() {
test("end()", function() { test("end()", function() {
expect(3); expect(3);
equals( "Yahoo", jQuery("#yahoo").parent().end().text(), "Check for end" ); equal( "Yahoo", jQuery("#yahoo").parent().end().text(), "Check for end" );
ok( jQuery("#yahoo").end(), "Check for end with nothing to end" ); ok( jQuery("#yahoo").end(), "Check for end with nothing to end" );
var x = jQuery("#yahoo"); var x = jQuery("#yahoo");
x.parent(); x.parent();
equals( "Yahoo", jQuery("#yahoo").text(), "Check for non-destructive behaviour" ); equal( "Yahoo", jQuery("#yahoo").text(), "Check for non-destructive behaviour" );
}); });
test("length", function() { test("length", function() {
expect(1); expect(1);
equals( jQuery("#qunit-fixture p").length, 6, "Get Number of Elements Found" ); equal( jQuery("#qunit-fixture p").length, 6, "Get Number of Elements Found" );
}); });
test("size()", function() { test("size()", function() {
expect(1); expect(1);
equals( jQuery("#qunit-fixture p").size(), 6, "Get Number of Elements Found" ); equal( jQuery("#qunit-fixture p").size(), 6, "Get Number of Elements Found" );
}); });
test("get()", function() { test("get()", function() {
expect(1); expect(1);
same( jQuery("#qunit-fixture p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" ); deepEqual( jQuery("#qunit-fixture p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
}); });
test("toArray()", function() { test("toArray()", function() {
expect(1); expect(1);
same( 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" )
}) })
...@@ -711,13 +711,13 @@ test("inArray()", function() { ...@@ -711,13 +711,13 @@ test("inArray()", function() {
test("get(Number)", function() { test("get(Number)", function() {
expect(2); expect(2);
equals( jQuery("#qunit-fixture p").get(0), document.getElementById("firstp"), "Get A Single Element" ); equal( jQuery("#qunit-fixture p").get(0), document.getElementById("firstp"), "Get A Single Element" );
strictEqual( jQuery("#firstp").get(1), undefined, "Try get with index larger elements count" ); strictEqual( jQuery("#firstp").get(1), undefined, "Try get with index larger elements count" );
}); });
test("get(-Number)",function() { test("get(-Number)",function() {
expect(2); expect(2);
equals( 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" );
}) })
...@@ -737,14 +737,14 @@ test("slice()", function() { ...@@ -737,14 +737,14 @@ test("slice()", function() {
var $links = jQuery("#ap a"); var $links = jQuery("#ap a");
same( $links.slice(1,2).get(), q("groups"), "slice(1,2)" ); deepEqual( $links.slice(1,2).get(), q("groups"), "slice(1,2)" );
same( $links.slice(1).get(), q("groups", "anchor1", "mark"), "slice(1)" ); deepEqual( $links.slice(1).get(), q("groups", "anchor1", "mark"), "slice(1)" );
same( $links.slice(0,3).get(), q("google", "groups", "anchor1"), "slice(0,3)" ); deepEqual( $links.slice(0,3).get(), q("google", "groups", "anchor1"), "slice(0,3)" );
same( $links.slice(-1).get(), q("mark"), "slice(-1)" ); deepEqual( $links.slice(-1).get(), q("mark"), "slice(-1)" );
same( $links.eq(1).get(), q("groups"), "eq(1)" ); deepEqual( $links.eq(1).get(), q("groups"), "eq(1)" );
same( $links.eq("2").get(), q("anchor1"), "eq('2')" ); deepEqual( $links.eq("2").get(), q("anchor1"), "eq('2')" );
same( $links.eq(-1).get(), q("mark"), "eq(-1)" ); deepEqual( $links.eq(-1).get(), q("mark"), "eq(-1)" );
}); });
test("first()/last()", function() { test("first()/last()", function() {
...@@ -752,17 +752,17 @@ test("first()/last()", function() { ...@@ -752,17 +752,17 @@ test("first()/last()", function() {
var $links = jQuery("#ap a"), $none = jQuery("asdf"); var $links = jQuery("#ap a"), $none = jQuery("asdf");
same( $links.first().get(), q("google"), "first()" ); deepEqual( $links.first().get(), q("google"), "first()" );
same( $links.last().get(), q("mark"), "last()" ); deepEqual( $links.last().get(), q("mark"), "last()" );
same( $none.first().get(), [], "first() none" ); deepEqual( $none.first().get(), [], "first() none" );
same( $none.last().get(), [], "last() none" ); deepEqual( $none.last().get(), [], "last() none" );
}); });
test("map()", function() { test("map()", function() {
expect(8); expect(8);
same( deepEqual(
jQuery("#ap").map(function(){ jQuery("#ap").map(function(){
return jQuery(this).find("a").get(); return jQuery(this).find("a").get();
}).get(), }).get(),
...@@ -770,7 +770,7 @@ test("map()", function() { ...@@ -770,7 +770,7 @@ test("map()", function() {
"Array Map" "Array Map"
); );
same( deepEqual(
jQuery("#ap > a").map(function(){ jQuery("#ap > a").map(function(){
return this.parentNode; return this.parentNode;
}).get(), }).get(),
...@@ -782,35 +782,35 @@ test("map()", function() { ...@@ -782,35 +782,35 @@ test("map()", function() {
var keys = jQuery.map( {a:1,b:2}, function( v, k ){ var keys = jQuery.map( {a:1,b:2}, function( v, k ){
return k; return k;
}); });
equals( 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 ){ var values = jQuery.map( {a:1,b:2}, function( v, k ){
return v; return v;
}); });
equals( 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 ){ var values = jQuery.map( {a:1,b:2, length:3}, function( v, k ){
return v; return v;
}); });
equals( 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"); var scripts = document.getElementsByTagName("script");
var mapped = jQuery.map( scripts, function( v, k ){ var mapped = jQuery.map( scripts, function( v, k ){
return v; return v;
}); });
equals( 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"); var nonsense = document.getElementsByTagName("asdf");
var mapped = jQuery.map( nonsense, function( v, k ){ var mapped = jQuery.map( nonsense, function( v, k ){
return v; return v;
}); });
equals( 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 ){ var 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
}); });
equals( flat.join(""), "00012223", "try the new flatten technique(#2616)" ); equal( flat.join(""), "00012223", "try the new flatten technique(#2616)" );
}); });
test("jQuery.merge()", function() { test("jQuery.merge()", function() {
...@@ -818,20 +818,20 @@ test("jQuery.merge()", function() { ...@@ -818,20 +818,20 @@ test("jQuery.merge()", function() {
var parse = jQuery.merge; var parse = jQuery.merge;
same( parse([],[]), [], "Empty arrays" ); deepEqual( parse([],[]), [], "Empty arrays" );
same( parse([1],[2]), [1,2], "Basic" ); deepEqual( parse([1],[2]), [1,2], "Basic" );
same( parse([1,2],[3,4]), [1,2,3,4], "Basic" ); deepEqual( parse([1,2],[3,4]), [1,2,3,4], "Basic" );
same( parse([1,2],[]), [1,2], "Second empty" ); deepEqual( parse([1,2],[]), [1,2], "Second empty" );
same( parse([],[1,2]), [1,2], "First empty" ); deepEqual( parse([],[1,2]), [1,2], "First empty" );
// Fixed at [5998], #3641 // Fixed at [5998], #3641
same( parse([-2,-1], [0,1,2]), [-2,-1,0,1,2], "Second array including a zero (falsy)"); deepEqual( parse([-2,-1], [0,1,2]), [-2,-1,0,1,2], "Second array including a zero (falsy)");
// After fixing #5527 // After fixing #5527
same( parse([], [null, undefined]), [null, undefined], "Second array including null and undefined values"); deepEqual( parse([], [null, undefined]), [null, undefined], "Second array including null and undefined values");
same( parse({length:0}, [1,2]), {length:2, 0:1, 1:2}, "First array like"); deepEqual( parse({length:0}, [1,2]), {length:2, 0:1, 1:2}, "First array like");
}); });
test("jQuery.extend(Object, Object)", function() { test("jQuery.extend(Object, Object)", function() {
...@@ -850,17 +850,17 @@ test("jQuery.extend(Object, Object)", function() { ...@@ -850,17 +850,17 @@ test("jQuery.extend(Object, Object)", function() {
nestedarray = { arr: arr }; nestedarray = { arr: arr };
jQuery.extend(settings, options); jQuery.extend(settings, options);
same( settings, merged, "Check if extended: settings must be extended" ); deepEqual( settings, merged, "Check if extended: settings must be extended" );
same( options, optionsCopy, "Check if not modified: options must not be modified" ); deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" );
jQuery.extend(settings, null, options); jQuery.extend(settings, null, options);
same( settings, merged, "Check if extended: settings must be extended" ); deepEqual( settings, merged, "Check if extended: settings must be extended" );
same( options, optionsCopy, "Check if not modified: options must not be modified" ); deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" );
jQuery.extend(true, deep1, deep2); jQuery.extend(true, deep1, deep2);
same( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" ); deepEqual( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
same( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" ); deepEqual( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" ); equal( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
ok( jQuery.extend(true, {}, nestedarray).arr !== arr, "Deep extend of object must clone child array" ); ok( jQuery.extend(true, {}, nestedarray).arr !== arr, "Deep extend of object must clone child array" );
...@@ -871,12 +871,12 @@ test("jQuery.extend(Object, Object)", function() { ...@@ -871,12 +871,12 @@ test("jQuery.extend(Object, Object)", function() {
var empty = {}; var empty = {};
var optionsWithLength = { foo: { length: -1 } }; var optionsWithLength = { foo: { length: -1 } };
jQuery.extend(true, empty, optionsWithLength); jQuery.extend(true, empty, optionsWithLength);
same( 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);
same( empty.foo, optionsWithDate.foo, "Dates copy correctly" ); deepEqual( empty.foo, optionsWithDate.foo, "Dates copy correctly" );
var myKlass = function() {}; var myKlass = function() {};
var customObject = new myKlass(); var customObject = new myKlass();
...@@ -907,10 +907,10 @@ test("jQuery.extend(Object, Object)", function() { ...@@ -907,10 +907,10 @@ test("jQuery.extend(Object, Object)", function() {
var target = {}; var target = {};
var recursive = { foo:target, bar:5 }; var recursive = { foo:target, bar:5 };
jQuery.extend(true, target, recursive); jQuery.extend(true, target, recursive);
same( 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 var ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
equals( 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] } ); var 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" );
...@@ -920,11 +920,11 @@ test("jQuery.extend(Object, Object)", function() { ...@@ -920,11 +920,11 @@ test("jQuery.extend(Object, Object)", function() {
var obj = { foo:null }; var obj = { foo:null };
jQuery.extend(true, obj, { foo:"notnull" } ); jQuery.extend(true, obj, { foo:"notnull" } );
equals( obj.foo, "notnull", "Make sure a null value can be overwritten" ); equal( obj.foo, "notnull", "Make sure a null value can be overwritten" );
function func() {} function func() {}
jQuery.extend(func, { key: "value" } ); jQuery.extend(func, { key: "value" } );
equals( func.key, "value", "Verify a function can be extended" ); equal( func.key, "value", "Verify a function can be extended" );
var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
...@@ -935,118 +935,118 @@ test("jQuery.extend(Object, Object)", function() { ...@@ -935,118 +935,118 @@ test("jQuery.extend(Object, Object)", function() {
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); var settings = jQuery.extend({}, defaults, options1, options2);
same( settings, merged2, "Check if extended: settings must be extended" ); deepEqual( settings, merged2, "Check if extended: settings must be extended" );
same( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" ); deepEqual( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
same( options1, options1Copy, "Check if not modified: options1 must not be modified" ); deepEqual( options1, options1Copy, "Check if not modified: options1 must not be modified" );
same( options2, options2Copy, "Check if not modified: options2 must not be modified" ); deepEqual( options2, options2Copy, "Check if not modified: options2 must not be modified" );
}); });
test("jQuery.each(Object,Function)", function() { test("jQuery.each(Object,Function)", function() {
expect(14); expect(14);
jQuery.each( [0,1,2], function(i, n){ jQuery.each( [0,1,2], function(i, n){
equals( i, n, "Check array iteration" ); equal( i, n, "Check array iteration" );
}); });
jQuery.each( [5,6,7], function(i, n){ jQuery.each( [5,6,7], function(i, n){
equals( i, n - 5, "Check array iteration" ); equal( i, n - 5, "Check array iteration" );
}); });
jQuery.each( { name: "name", lang: "lang" }, function(i, n){ jQuery.each( { name: "name", lang: "lang" }, function(i, n){
equals( i, n, "Check object iteration" ); equal( i, n, "Check object iteration" );
}); });
var total = 0; var total = 0;
jQuery.each([1,2,3], function(i,v){ total += v; }); jQuery.each([1,2,3], function(i,v){ total += v; });
equals( 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; });
equals( 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; });
equals( total, 6, "Looping over an object" ); equal( total, 6, "Looping over an object" );
total = 0; total = 0;
jQuery.each({"a":3,"b":3,"c":3}, function(i,v){ total += v; return false; }); jQuery.each({"a":3,"b":3,"c":3}, function(i,v){ total += v; return false; });
equals( total, 3, "Looping over an object, with break" ); equal( total, 3, "Looping over an object, with break" );
var f = function(){}; var f = function(){};
f.foo = "bar"; f.foo = "bar";
jQuery.each(f, function(i){ jQuery.each(f, function(i){
f[i] = "baz"; f[i] = "baz";
}); });
equals( "baz", f.foo, "Loop over a function" ); equal( "baz", f.foo, "Loop over a function" );
var stylesheet_count = 0; var stylesheet_count = 0;
jQuery.each(document.styleSheets, function(i){ jQuery.each(document.styleSheets, function(i){
stylesheet_count++; stylesheet_count++;
}); });
equals(stylesheet_count, 2, "should not throw an error in IE while looping over document.styleSheets and return proper amount"); equal(stylesheet_count, 2, "should not throw an error in IE while looping over document.styleSheets and return proper amount");
}); });
test("jQuery.makeArray", function(){ test("jQuery.makeArray", function(){
expect(17); expect(17);
equals( jQuery.makeArray(jQuery("html>*"))[0].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" ); equal( jQuery.makeArray(jQuery("html>*"))[0].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" );
equals( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" ); equal( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" );
equals( (function(){ return jQuery.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" ); equal( (function(){ return jQuery.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" );
equals( jQuery.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" ); equal( jQuery.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" );
equals( jQuery.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" ); equal( jQuery.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" );
equals( jQuery.makeArray( 0 )[0], 0 , "Pass makeArray a number" ); equal( jQuery.makeArray( 0 )[0], 0 , "Pass makeArray a number" );
equals( jQuery.makeArray( "foo" )[0], "foo", "Pass makeArray a string" ); equal( jQuery.makeArray( "foo" )[0], "foo", "Pass makeArray a string" );
equals( jQuery.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" ); equal( jQuery.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" );
equals( jQuery.makeArray( document.createElement("div") )[0].nodeName.toUpperCase(), "DIV", "Pass makeArray a single node" ); equal( jQuery.makeArray( document.createElement("div") )[0].nodeName.toUpperCase(), "DIV", "Pass makeArray a single node" );
equals( jQuery.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" ); equal( jQuery.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" );
ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "Pass makeArray a childNodes array" ); ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "Pass makeArray a childNodes array" );
// function, is tricky as it has length // function, is tricky as it has length
equals( jQuery.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" ); equal( jQuery.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" );
//window, also has length //window, also has length
equals( jQuery.makeArray(window)[0], window, "Pass makeArray the window" ); equal( jQuery.makeArray(window)[0], window, "Pass makeArray the window" );
equals( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" ); equal( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
ok( jQuery.makeArray(document.getElementById("form")).length >= 13, "Pass makeArray a form (treat as elements)" ); ok( jQuery.makeArray(document.getElementById("form")).length >= 13, "Pass makeArray a form (treat as elements)" );
// For #5610 // For #5610
same( jQuery.makeArray({length: "0"}), [], "Make sure object is coerced properly."); deepEqual( jQuery.makeArray({length: "0"}), [], "Make sure object is coerced properly.");
same( jQuery.makeArray({length: "5"}), [], "Make sure object is coerced properly."); deepEqual( jQuery.makeArray({length: "5"}), [], "Make sure object is coerced properly.");
}); });
test("jQuery.inArray", function(){ test("jQuery.inArray", function(){
expect(3); expect(3);
equals( jQuery.inArray( 0, false ), -1 , "Search in 'false' as array returns -1 and doesn't throw exception" ); equal( jQuery.inArray( 0, false ), -1 , "Search in 'false' as array returns -1 and doesn't throw exception" );
equals( jQuery.inArray( 0, null ), -1 , "Search in 'null' as array returns -1 and doesn't throw exception" ); equal( jQuery.inArray( 0, null ), -1 , "Search in 'null' as array returns -1 and doesn't throw exception" );
equals( jQuery.inArray( 0, undefined ), -1 , "Search in 'undefined' as array returns -1 and doesn't throw exception" ); equal( jQuery.inArray( 0, undefined ), -1 , "Search in 'undefined' as array returns -1 and doesn't throw exception" );
}); });
test("jQuery.isEmptyObject", function(){ test("jQuery.isEmptyObject", function(){
expect(2); expect(2);
equals(true, jQuery.isEmptyObject({}), "isEmptyObject on empty object literal" ); equal(true, jQuery.isEmptyObject({}), "isEmptyObject on empty object literal" );
equals(false, jQuery.isEmptyObject({a:1}), "isEmptyObject on non-empty object literal" ); equal(false, jQuery.isEmptyObject({a:1}), "isEmptyObject on non-empty object literal" );
// What about this ? // What about this ?
// equals(true, jQuery.isEmptyObject(null), "isEmptyObject on null" ); // equal(true, jQuery.isEmptyObject(null), "isEmptyObject on null" );
}); });
test("jQuery.proxy", function(){ test("jQuery.proxy", function(){
expect(7); expect(7);
var test = function(){ equals( this, thisObject, "Make sure that scope is set properly." ); }; var test = function(){ equal( this, thisObject, "Make sure that scope is set properly." ); };
var thisObject = { foo: "bar", method: test }; var thisObject = { foo: "bar", method: test };
// Make sure normal works // Make sure normal works
...@@ -1059,32 +1059,32 @@ test("jQuery.proxy", function(){ ...@@ -1059,32 +1059,32 @@ test("jQuery.proxy", function(){
jQuery.proxy( thisObject, "method" )(); jQuery.proxy( thisObject, "method" )();
// Make sure it doesn't freak out // Make sure it doesn't freak out
equals( jQuery.proxy( null, thisObject ), undefined, "Make sure no function was returned." ); equal( jQuery.proxy( null, thisObject ), undefined, "Make sure no function was returned." );
// Partial application // Partial application
var test2 = function( a ){ equals( a, "pre-applied", "Ensure arguments can be pre-applied." ); }; var test2 = function( a ){ equal( a, "pre-applied", "Ensure arguments can be pre-applied." ); };
jQuery.proxy( test2, null, "pre-applied" )(); jQuery.proxy( test2, null, "pre-applied" )();
// Partial application w/ normal arguments // Partial application w/ normal arguments
var test3 = function( a, b ){ equals( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); }; var test3 = function( a, b ){ equal( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); };
jQuery.proxy( test3, null, "pre-applied" )( "normal" ); jQuery.proxy( test3, null, "pre-applied" )( "normal" );
// Test old syntax // Test old syntax
var test4 = { meth: function( a ){ equals( a, "boom", "Ensure old syntax works." ); } }; var test4 = { meth: function( a ){ equal( a, "boom", "Ensure old syntax works." ); } };
jQuery.proxy( test4, "meth" )( "boom" ); jQuery.proxy( test4, "meth" )( "boom" );
}); });
test("jQuery.parseJSON", function(){ test("jQuery.parseJSON", function(){
expect(8); expect(8);
equals( jQuery.parseJSON(), null, "Nothing in, null out." ); equal( jQuery.parseJSON(), null, "Nothing in, null out." );
equals( jQuery.parseJSON( null ), null, "Nothing in, null out." ); equal( jQuery.parseJSON( null ), null, "Nothing in, null out." );
equals( jQuery.parseJSON( "" ), null, "Nothing in, null out." ); equal( jQuery.parseJSON( "" ), null, "Nothing in, null out." );
same( jQuery.parseJSON("{}"), {}, "Plain object parsing." ); deepEqual( jQuery.parseJSON("{}"), {}, "Plain object parsing." );
same( jQuery.parseJSON("{\"test\":1}"), {"test":1}, "Plain object parsing." ); deepEqual( jQuery.parseJSON("{\"test\":1}"), {"test":1}, "Plain object parsing." );
same( jQuery.parseJSON("\n{\"test\":1}"), {"test":1}, "Make sure leading whitespaces are handled." ); deepEqual( jQuery.parseJSON("\n{\"test\":1}"), {"test":1}, "Make sure leading whitespaces are handled." );
try { try {
jQuery.parseJSON("{a:1}"); jQuery.parseJSON("{a:1}");
...@@ -1139,7 +1139,7 @@ test("jQuery.sub() - Static Methods", function(){ ...@@ -1139,7 +1139,7 @@ test("jQuery.sub() - Static Methods", function(){
//Test Simple Subclass //Test Simple Subclass
ok(Subclass.topLevelMethod() === false, "Subclass.topLevelMethod thought debug was true"); ok(Subclass.topLevelMethod() === false, "Subclass.topLevelMethod thought debug was true");
ok(Subclass.config.locale == "en_US", Subclass.config.locale + " is wrong!"); ok(Subclass.config.locale == "en_US", Subclass.config.locale + " is wrong!");
same(Subclass.config.test, undefined, "Subclass.config.test is set incorrectly"); deepEqual(Subclass.config.test, undefined, "Subclass.config.test is set incorrectly");
equal(jQuery.ajax, Subclass.ajax, "The subclass failed to get all top level methods"); equal(jQuery.ajax, Subclass.ajax, "The subclass failed to get all top level methods");
//Create a SubSubclass //Create a SubSubclass
...@@ -1148,7 +1148,7 @@ test("jQuery.sub() - Static Methods", function(){ ...@@ -1148,7 +1148,7 @@ test("jQuery.sub() - Static Methods", function(){
//Make Sure the SubSubclass inherited properly //Make Sure the SubSubclass inherited properly
ok(SubSubclass.topLevelMethod() === false, "SubSubclass.topLevelMethod thought debug was true"); ok(SubSubclass.topLevelMethod() === false, "SubSubclass.topLevelMethod thought debug was true");
ok(SubSubclass.config.locale == "en_US", SubSubclass.config.locale + " is wrong!"); ok(SubSubclass.config.locale == "en_US", SubSubclass.config.locale + " is wrong!");
same(SubSubclass.config.test, undefined, "SubSubclass.config.test is set incorrectly"); deepEqual(SubSubclass.config.test, undefined, "SubSubclass.config.test is set incorrectly");
equal(jQuery.ajax, SubSubclass.ajax, "The subsubclass failed to get all top level methods"); equal(jQuery.ajax, SubSubclass.ajax, "The subsubclass failed to get all top level methods");
//Modify The Subclass and test the Modifications //Modify The Subclass and test the Modifications
...@@ -1157,7 +1157,7 @@ test("jQuery.sub() - Static Methods", function(){ ...@@ -1157,7 +1157,7 @@ test("jQuery.sub() - Static Methods", function(){
SubSubclass.debug = true; SubSubclass.debug = true;
SubSubclass.ajax = function() {return false;}; SubSubclass.ajax = function() {return false;};
ok(SubSubclass.topLevelMethod(), "SubSubclass.topLevelMethod thought debug was false"); ok(SubSubclass.topLevelMethod(), "SubSubclass.topLevelMethod thought debug was false");
same(SubSubclass(document).subClassMethod, Subclass.fn.subClassMethod, "Methods Differ!"); deepEqual(SubSubclass(document).subClassMethod, Subclass.fn.subClassMethod, "Methods Differ!");
ok(SubSubclass.config.locale == "es_MX", SubSubclass.config.locale + " is wrong!"); ok(SubSubclass.config.locale == "es_MX", SubSubclass.config.locale + " is wrong!");
ok(SubSubclass.config.test == "worked", "SubSubclass.config.test is set incorrectly"); ok(SubSubclass.config.test == "worked", "SubSubclass.config.test is set incorrectly");
notEqual(jQuery.ajax, SubSubclass.ajax, "The subsubclass failed to get all top level methods"); notEqual(jQuery.ajax, SubSubclass.ajax, "The subsubclass failed to get all top level methods");
...@@ -1165,8 +1165,8 @@ test("jQuery.sub() - Static Methods", function(){ ...@@ -1165,8 +1165,8 @@ test("jQuery.sub() - Static Methods", function(){
//This shows that the modifications to the SubSubClass did not bubble back up to it's superclass //This shows that the modifications to the SubSubClass did not bubble back up to it's superclass
ok(Subclass.topLevelMethod() === false, "Subclass.topLevelMethod thought debug was true"); ok(Subclass.topLevelMethod() === false, "Subclass.topLevelMethod thought debug was true");
ok(Subclass.config.locale == "en_US", Subclass.config.locale + " is wrong!"); ok(Subclass.config.locale == "en_US", Subclass.config.locale + " is wrong!");
same(Subclass.config.test, undefined, "Subclass.config.test is set incorrectly"); deepEqual(Subclass.config.test, undefined, "Subclass.config.test is set incorrectly");
same(Subclass(document).subSubClassMethod, undefined, "subSubClassMethod set incorrectly"); deepEqual(Subclass(document).subSubClassMethod, undefined, "subSubClassMethod set incorrectly");
equal(jQuery.ajax, Subclass.ajax, "The subclass failed to get all top level methods"); equal(jQuery.ajax, Subclass.ajax, "The subclass failed to get all top level methods");
}); });
...@@ -1211,27 +1211,27 @@ test("jQuery.sub() - .fn Methods", function(){ ...@@ -1211,27 +1211,27 @@ test("jQuery.sub() - .fn Methods", function(){
description = "(\""+selector+"\", "+context+")."+method+"("+(arg||"")+")"; description = "(\""+selector+"\", "+context+")."+method+"("+(arg||"")+")";
same( deepEqual(
jQuery(selector, context)[method](arg).subclassMethod, undefined, jQuery(selector, context)[method](arg).subclassMethod, undefined,
"jQuery"+description+" doesn't have Subclass methods" "jQuery"+description+" doesn't have Subclass methods"
); );
same( deepEqual(
jQuery(selector, context)[method](arg).subclassSubclassMethod, undefined, jQuery(selector, context)[method](arg).subclassSubclassMethod, undefined,
"jQuery"+description+" doesn't have SubclassSubclass methods" "jQuery"+description+" doesn't have SubclassSubclass methods"
); );
same( deepEqual(
Subclass(selector, context)[method](arg).subclassMethod, Subclass.fn.subclassMethod, Subclass(selector, context)[method](arg).subclassMethod, Subclass.fn.subclassMethod,
"Subclass"+description+" has Subclass methods" "Subclass"+description+" has Subclass methods"
); );
same( deepEqual(
Subclass(selector, context)[method](arg).subclassSubclassMethod, undefined, Subclass(selector, context)[method](arg).subclassSubclassMethod, undefined,
"Subclass"+description+" doesn't have SubclassSubclass methods" "Subclass"+description+" doesn't have SubclassSubclass methods"
); );
same( deepEqual(
SubclassSubclass(selector, context)[method](arg).subclassMethod, Subclass.fn.subclassMethod, SubclassSubclass(selector, context)[method](arg).subclassMethod, Subclass.fn.subclassMethod,
"SubclassSubclass"+description+" has Subclass methods" "SubclassSubclass"+description+" has Subclass methods"
); );
same( deepEqual(
SubclassSubclass(selector, context)[method](arg).subclassSubclassMethod, SubclassSubclass.fn.subclassSubclassMethod, SubclassSubclass(selector, context)[method](arg).subclassSubclassMethod, SubclassSubclass.fn.subclassSubclassMethod,
"SubclassSubclass"+description+" has SubclassSubclass methods" "SubclassSubclass"+description+" has SubclassSubclass methods"
); );
......
...@@ -3,7 +3,7 @@ module("css", { teardown: moduleTeardown }); ...@@ -3,7 +3,7 @@ module("css", { teardown: moduleTeardown });
test("css(String|Hash)", function() { test("css(String|Hash)", function() {
expect( 44 ); expect( 44 );
equals( jQuery("#qunit-fixture").css("display"), "block", "Check for css property \"display\""); equal( jQuery("#qunit-fixture").css("display"), "block", "Check for css property \"display\"");
ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible"); ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible");
jQuery("#nothiddendiv").css({display: "none"}); jQuery("#nothiddendiv").css({display: "none"});
...@@ -17,19 +17,19 @@ test("css(String|Hash)", function() { ...@@ -17,19 +17,19 @@ test("css(String|Hash)", function() {
// These should be "auto" (or some better value) // These should be "auto" (or some better value)
// temporarily provide "0px" for backwards compat // temporarily provide "0px" for backwards compat
equals( div.css("width"), "0px", "Width on disconnected node." ); equal( div.css("width"), "0px", "Width on disconnected node." );
equals( div.css("height"), "0px", "Height on disconnected node." ); equal( div.css("height"), "0px", "Height on disconnected node." );
div.css({ width: 4, height: 4 }); div.css({ width: 4, height: 4 });
equals( div.css("width"), "4px", "Width on disconnected node." ); equal( div.css("width"), "4px", "Width on disconnected node." );
equals( div.css("height"), "4px", "Height on disconnected node." ); equal( div.css("height"), "4px", "Height on disconnected node." );
var div2 = jQuery( "<div style='display:none;'><input type='text' style='height:20px;'/><textarea style='height:20px;'/><div style='height:20px;'></div></div>").appendTo("body"); var div2 = jQuery( "<div style='display:none;'><input type='text' style='height:20px;'/><textarea style='height:20px;'/><div style='height:20px;'></div></div>").appendTo("body");
equals( div2.find("input").css("height"), "20px", "Height on hidden input." ); equal( div2.find("input").css("height"), "20px", "Height on hidden input." );
equals( div2.find("textarea").css("height"), "20px", "Height on hidden textarea." ); equal( div2.find("textarea").css("height"), "20px", "Height on hidden textarea." );
equals( div2.find("div").css("height"), "20px", "Height on hidden textarea." ); equal( div2.find("div").css("height"), "20px", "Height on hidden textarea." );
div2.remove(); div2.remove();
...@@ -38,28 +38,28 @@ test("css(String|Hash)", function() { ...@@ -38,28 +38,28 @@ test("css(String|Hash)", function() {
var width = parseFloat(jQuery("#nothiddendiv").css("width")), height = parseFloat(jQuery("#nothiddendiv").css("height")); var width = parseFloat(jQuery("#nothiddendiv").css("width")), height = parseFloat(jQuery("#nothiddendiv").css("height"));
jQuery("#nothiddendiv").css({ width: -1, height: -1 }); jQuery("#nothiddendiv").css({ width: -1, height: -1 });
equals( parseFloat(jQuery("#nothiddendiv").css("width")), width, "Test negative width ignored"); equal( parseFloat(jQuery("#nothiddendiv").css("width")), width, "Test negative width ignored");
equals( parseFloat(jQuery("#nothiddendiv").css("height")), height, "Test negative height ignored"); equal( parseFloat(jQuery("#nothiddendiv").css("height")), height, "Test negative height ignored");
equals( jQuery("<div style='display: none;'>").css("display"), "none", "Styles on disconnected nodes"); equal( jQuery("<div style='display: none;'>").css("display"), "none", "Styles on disconnected nodes");
jQuery("#floatTest").css({"float": "right"}); jQuery("#floatTest").css({"float": "right"});
equals( jQuery("#floatTest").css("float"), "right", "Modified CSS float using \"float\": Assert float is right"); equal( jQuery("#floatTest").css("float"), "right", "Modified CSS float using \"float\": Assert float is right");
jQuery("#floatTest").css({"font-size": "30px"}); jQuery("#floatTest").css({"font-size": "30px"});
equals( jQuery("#floatTest").css("font-size"), "30px", "Modified CSS font-size: Assert font-size is 30px"); equal( jQuery("#floatTest").css("font-size"), "30px", "Modified CSS font-size: Assert font-size is 30px");
jQuery.each("0,0.25,0.5,0.75,1".split(","), function(i, n) { jQuery.each("0,0.25,0.5,0.75,1".split(","), function(i, n) {
jQuery("#foo").css({opacity: n}); jQuery("#foo").css({opacity: n});
equals( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" ); equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
jQuery("#foo").css({opacity: parseFloat(n)}); jQuery("#foo").css({opacity: parseFloat(n)});
equals( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" ); equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
}); });
jQuery("#foo").css({opacity: ""}); jQuery("#foo").css({opacity: ""});
equals( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when set to an empty String" ); equal( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when set to an empty String" );
equals( jQuery("#empty").css("opacity"), "0", "Assert opacity is accessible via filter property set in stylesheet in IE" ); equal( jQuery("#empty").css("opacity"), "0", "Assert opacity is accessible via filter property set in stylesheet in IE" );
jQuery("#empty").css({ opacity: "1" }); jQuery("#empty").css({ opacity: "1" });
equals( jQuery("#empty").css("opacity"), "1", "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" ); equal( jQuery("#empty").css("opacity"), "1", "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" );
jQuery.support.opacity ? jQuery.support.opacity ?
ok(true, "Requires the same number of tests"): ok(true, "Requires the same number of tests"):
ok( ~jQuery("#empty")[0].currentStyle.filter.indexOf("gradient"), "Assert setting opacity doesn't overwrite other filters of the stylesheet in IE" ); ok( ~jQuery("#empty")[0].currentStyle.filter.indexOf("gradient"), "Assert setting opacity doesn't overwrite other filters of the stylesheet in IE" );
...@@ -67,16 +67,16 @@ test("css(String|Hash)", function() { ...@@ -67,16 +67,16 @@ test("css(String|Hash)", function() {
div = jQuery("#nothiddendiv"); div = jQuery("#nothiddendiv");
var child = jQuery("#nothiddendivchild"); var child = jQuery("#nothiddendivchild");
equals( parseInt(div.css("fontSize")), 16, "Verify fontSize px set." ); equal( parseInt(div.css("fontSize")), 16, "Verify fontSize px set." );
equals( parseInt(div.css("font-size")), 16, "Verify fontSize px set." ); equal( parseInt(div.css("font-size")), 16, "Verify fontSize px set." );
equals( parseInt(child.css("fontSize")), 16, "Verify fontSize px set." ); equal( parseInt(child.css("fontSize")), 16, "Verify fontSize px set." );
equals( parseInt(child.css("font-size")), 16, "Verify fontSize px set." ); equal( parseInt(child.css("font-size")), 16, "Verify fontSize px set." );
child.css("height", "100%"); child.css("height", "100%");
equals( 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");
equals( parseInt(child.css("fontSize")), 32, "Verify fontSize em set." ); equal( parseInt(child.css("fontSize")), 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
...@@ -86,29 +86,29 @@ test("css(String|Hash)", function() { ...@@ -86,29 +86,29 @@ test("css(String|Hash)", function() {
checkval = prctval; checkval = prctval;
} }
equals( prctval, checkval, "Verify fontSize % set." ); equal( prctval, checkval, "Verify fontSize % set." );
equals( typeof child.css("width"), "string", "Make sure that a string width is returned from css('width')." ); equal( typeof child.css("width"), "string", "Make sure that a string width is returned from css('width')." );
var old = child[0].style.height; var old = child[0].style.height;
// Test NaN // Test NaN
child.css("height", parseFloat("zoo")); child.css("height", parseFloat("zoo"));
equals( child[0].style.height, old, "Make sure height isn't changed on NaN." ); equal( child[0].style.height, old, "Make sure height isn't changed on NaN." );
// Test null // Test null
child.css("height", null); child.css("height", null);
equals( child[0].style.height, old, "Make sure height isn't changed on null." ); equal( child[0].style.height, old, "Make sure height isn't changed on null." );
old = child[0].style.fontSize; old = child[0].style.fontSize;
// Test NaN // Test NaN
child.css("font-size", parseFloat("zoo")); child.css("font-size", parseFloat("zoo"));
equals( child[0].style.fontSize, old, "Make sure font-size isn't changed on NaN." ); equal( child[0].style.fontSize, old, "Make sure font-size isn't changed on NaN." );
// Test null // Test null
child.css("font-size", null); child.css("font-size", null);
equals( child[0].style.fontSize, old, "Make sure font-size isn't changed on null." ); equal( child[0].style.fontSize, old, "Make sure font-size isn't changed on null." );
}); });
test("css() explicit and relative values", function() { test("css() explicit and relative values", function() {
...@@ -116,87 +116,87 @@ test("css() explicit and relative values", function() { ...@@ -116,87 +116,87 @@ test("css() explicit and relative values", function() {
var $elem = jQuery("#nothiddendiv"); var $elem = jQuery("#nothiddendiv");
$elem.css({ width: 1, height: 1, paddingLeft: "1px", opacity: 1 }); $elem.css({ width: 1, height: 1, paddingLeft: "1px", opacity: 1 });
equals( $elem.width(), 1, "Initial css set or width/height works (hash)" ); equal( $elem.width(), 1, "Initial css set or width/height works (hash)" );
equals( $elem.css("paddingLeft"), "1px", "Initial css set of paddingLeft works (hash)" ); equal( $elem.css("paddingLeft"), "1px", "Initial css set of paddingLeft works (hash)" );
equals( $elem.css("opacity"), "1", "Initial css set of opacity works (hash)" ); equal( $elem.css("opacity"), "1", "Initial css set of opacity works (hash)" );
$elem.css({ width: "+=9" }); $elem.css({ width: "+=9" });
equals( $elem.width(), 10, "'+=9' on width (hash)" ); equal( $elem.width(), 10, "'+=9' on width (hash)" );
$elem.css({ width: "-=9" }); $elem.css({ width: "-=9" });
equals( $elem.width(), 1, "'-=9' on width (hash)" ); equal( $elem.width(), 1, "'-=9' on width (hash)" );
$elem.css({ width: "+=9px" }); $elem.css({ width: "+=9px" });
equals( $elem.width(), 10, "'+=9px' on width (hash)" ); equal( $elem.width(), 10, "'+=9px' on width (hash)" );
$elem.css({ width: "-=9px" }); $elem.css({ width: "-=9px" });
equals( $elem.width(), 1, "'-=9px' on width (hash)" ); equal( $elem.width(), 1, "'-=9px' on width (hash)" );
$elem.css( "width", "+=9" ); $elem.css( "width", "+=9" );
equals( $elem.width(), 10, "'+=9' on width (params)" ); equal( $elem.width(), 10, "'+=9' on width (params)" );
$elem.css( "width", "-=9" ) ; $elem.css( "width", "-=9" ) ;
equals( $elem.width(), 1, "'-=9' on width (params)" ); equal( $elem.width(), 1, "'-=9' on width (params)" );
$elem.css( "width", "+=9px" ); $elem.css( "width", "+=9px" );
equals( $elem.width(), 10, "'+=9px' on width (params)" ); equal( $elem.width(), 10, "'+=9px' on width (params)" );
$elem.css( "width", "-=9px" ); $elem.css( "width", "-=9px" );
equals( $elem.width(), 1, "'-=9px' on width (params)" ); equal( $elem.width(), 1, "'-=9px' on width (params)" );
$elem.css( "width", "-=-9px" ); $elem.css( "width", "-=-9px" );
equals( $elem.width(), 10, "'-=-9px' on width (params)" ); equal( $elem.width(), 10, "'-=-9px' on width (params)" );
$elem.css( "width", "+=-9px" ); $elem.css( "width", "+=-9px" );
equals( $elem.width(), 1, "'+=-9px' on width (params)" ); equal( $elem.width(), 1, "'+=-9px' on width (params)" );
$elem.css({ paddingLeft: "+=4" }); $elem.css({ paddingLeft: "+=4" });
equals( $elem.css("paddingLeft"), "5px", "'+=4' on paddingLeft (hash)" ); equal( $elem.css("paddingLeft"), "5px", "'+=4' on paddingLeft (hash)" );
$elem.css({ paddingLeft: "-=4" }); $elem.css({ paddingLeft: "-=4" });
equals( $elem.css("paddingLeft"), "1px", "'-=4' on paddingLeft (hash)" ); equal( $elem.css("paddingLeft"), "1px", "'-=4' on paddingLeft (hash)" );
$elem.css({ paddingLeft: "+=4px" }); $elem.css({ paddingLeft: "+=4px" });
equals( $elem.css("paddingLeft"), "5px", "'+=4px' on paddingLeft (hash)" ); equal( $elem.css("paddingLeft"), "5px", "'+=4px' on paddingLeft (hash)" );
$elem.css({ paddingLeft: "-=4px" }); $elem.css({ paddingLeft: "-=4px" });
equals( $elem.css("paddingLeft"), "1px", "'-=4px' on paddingLeft (hash)" ); equal( $elem.css("paddingLeft"), "1px", "'-=4px' on paddingLeft (hash)" );
$elem.css({ "padding-left": "+=4" }); $elem.css({ "padding-left": "+=4" });
equals( $elem.css("paddingLeft"), "5px", "'+=4' on padding-left (hash)" ); equal( $elem.css("paddingLeft"), "5px", "'+=4' on padding-left (hash)" );
$elem.css({ "padding-left": "-=4" }); $elem.css({ "padding-left": "-=4" });
equals( $elem.css("paddingLeft"), "1px", "'-=4' on padding-left (hash)" ); equal( $elem.css("paddingLeft"), "1px", "'-=4' on padding-left (hash)" );
$elem.css({ "padding-left": "+=4px" }); $elem.css({ "padding-left": "+=4px" });
equals( $elem.css("paddingLeft"), "5px", "'+=4px' on padding-left (hash)" ); equal( $elem.css("paddingLeft"), "5px", "'+=4px' on padding-left (hash)" );
$elem.css({ "padding-left": "-=4px" }); $elem.css({ "padding-left": "-=4px" });
equals( $elem.css("paddingLeft"), "1px", "'-=4px' on padding-left (hash)" ); equal( $elem.css("paddingLeft"), "1px", "'-=4px' on padding-left (hash)" );
$elem.css( "paddingLeft", "+=4" ); $elem.css( "paddingLeft", "+=4" );
equals( $elem.css("paddingLeft"), "5px", "'+=4' on paddingLeft (params)" ); equal( $elem.css("paddingLeft"), "5px", "'+=4' on paddingLeft (params)" );
$elem.css( "paddingLeft", "-=4" ); $elem.css( "paddingLeft", "-=4" );
equals( $elem.css("paddingLeft"), "1px", "'-=4' on paddingLeft (params)" ); equal( $elem.css("paddingLeft"), "1px", "'-=4' on paddingLeft (params)" );
$elem.css( "padding-left", "+=4px" ); $elem.css( "padding-left", "+=4px" );
equals( $elem.css("paddingLeft"), "5px", "'+=4px' on padding-left (params)" ); equal( $elem.css("paddingLeft"), "5px", "'+=4px' on padding-left (params)" );
$elem.css( "padding-left", "-=4px" ); $elem.css( "padding-left", "-=4px" );
equals( $elem.css("paddingLeft"), "1px", "'-=4px' on padding-left (params)" ); equal( $elem.css("paddingLeft"), "1px", "'-=4px' on padding-left (params)" );
$elem.css({ opacity: "-=0.5" }); $elem.css({ opacity: "-=0.5" });
equals( $elem.css("opacity"), "0.5", "'-=0.5' on opacity (hash)" ); equal( $elem.css("opacity"), "0.5", "'-=0.5' on opacity (hash)" );
$elem.css({ opacity: "+=0.5" }); $elem.css({ opacity: "+=0.5" });
equals( $elem.css("opacity"), "1", "'+=0.5' on opacity (hash)" ); equal( $elem.css("opacity"), "1", "'+=0.5' on opacity (hash)" );
$elem.css( "opacity", "-=0.5" ); $elem.css( "opacity", "-=0.5" );
equals( $elem.css("opacity"), "0.5", "'-=0.5' on opacity (params)" ); equal( $elem.css("opacity"), "0.5", "'-=0.5' on opacity (params)" );
$elem.css( "opacity", "+=0.5" ); $elem.css( "opacity", "+=0.5" );
equals( $elem.css("opacity"), "1", "'+=0.5' on opacity (params)" ); equal( $elem.css("opacity"), "1", "'+=0.5' on opacity (params)" );
}); });
test("css(String, Object)", function() { test("css(String, Object)", function() {
...@@ -212,33 +212,33 @@ test("css(String, Object)", function() { ...@@ -212,33 +212,33 @@ test("css(String, Object)", function() {
ok( jQuery("#nothiddendiv").css("top"), -16, "Check negative number in EMs." ); ok( jQuery("#nothiddendiv").css("top"), -16, "Check negative number in EMs." );
jQuery("#floatTest").css("float", "left"); jQuery("#floatTest").css("float", "left");
equals( jQuery("#floatTest").css("float"), "left", "Modified CSS float using \"float\": Assert float is left"); equal( jQuery("#floatTest").css("float"), "left", "Modified CSS float using \"float\": Assert float is left");
jQuery("#floatTest").css("font-size", "20px"); jQuery("#floatTest").css("font-size", "20px");
equals( jQuery("#floatTest").css("font-size"), "20px", "Modified CSS font-size: Assert font-size is 20px"); equal( jQuery("#floatTest").css("font-size"), "20px", "Modified CSS font-size: Assert font-size is 20px");
jQuery.each("0,0.25,0.5,0.75,1".split(","), function(i, n) { jQuery.each("0,0.25,0.5,0.75,1".split(","), function(i, n) {
jQuery("#foo").css("opacity", n); jQuery("#foo").css("opacity", n);
equals( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" ); equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
jQuery("#foo").css("opacity", parseFloat(n)); jQuery("#foo").css("opacity", parseFloat(n));
equals( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" ); equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
}); });
jQuery("#foo").css("opacity", ""); jQuery("#foo").css("opacity", "");
equals( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when set to an empty String" ); equal( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when set to an empty String" );
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents(); var j = jQuery("#nonnodes").contents();
j.css("overflow", "visible"); j.css("overflow", "visible");
equals( j.css("overflow"), "visible", "Check node,textnode,comment css works" ); equal( j.css("overflow"), "visible", "Check node,textnode,comment css works" );
// opera sometimes doesn't update 'display' correctly, see #2037 // opera sometimes doesn't update 'display' correctly, see #2037
jQuery("#t2037")[0].innerHTML = jQuery("#t2037")[0].innerHTML; jQuery("#t2037")[0].innerHTML = jQuery("#t2037")[0].innerHTML;
equals( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" ); equal( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
var div = jQuery("#nothiddendiv"), var div = jQuery("#nothiddendiv"),
display = div.css("display"), display = div.css("display"),
ret = div.css("display", undefined); ret = div.css("display", undefined);
equals( ret, div, "Make sure setting undefined returns the original set." ); equal( ret, div, "Make sure setting undefined returns the original set." );
equals( div.css("display"), display, "Make sure that the display wasn't changed." ); equal( div.css("display"), display, "Make sure that the display wasn't changed." );
// Test for Bug #5509 // Test for Bug #5509
var success = true; var success = true;
...@@ -255,16 +255,16 @@ if ( !jQuery.support.opacity ) { ...@@ -255,16 +255,16 @@ if ( !jQuery.support.opacity ) {
test("css(String, Object) for MSIE", function() { test("css(String, Object) for MSIE", function() {
// for #1438, IE throws JS error when filter exists but doesn't have opacity in it // for #1438, IE throws JS error when filter exists but doesn't have opacity in it
jQuery("#foo").css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');"); jQuery("#foo").css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
equals( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when a different filter is set in IE, #1438" ); equal( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when a different filter is set in IE, #1438" );
var filterVal = "progid:DXImageTransform.Microsoft.Alpha(opacity=30) progid:DXImageTransform.Microsoft.Blur(pixelradius=5)"; var filterVal = "progid:DXImageTransform.Microsoft.Alpha(opacity=30) progid:DXImageTransform.Microsoft.Blur(pixelradius=5)";
var filterVal2 = "progid:DXImageTransform.Microsoft.alpha(opacity=100) progid:DXImageTransform.Microsoft.Blur(pixelradius=5)"; var filterVal2 = "progid:DXImageTransform.Microsoft.alpha(opacity=100) progid:DXImageTransform.Microsoft.Blur(pixelradius=5)";
var filterVal3 = "progid:DXImageTransform.Microsoft.Blur(pixelradius=5)"; var filterVal3 = "progid:DXImageTransform.Microsoft.Blur(pixelradius=5)";
jQuery("#foo").css("filter", filterVal); jQuery("#foo").css("filter", filterVal);
equals( jQuery("#foo").css("filter"), filterVal, "css('filter', val) works" ); equal( jQuery("#foo").css("filter"), filterVal, "css('filter', val) works" );
jQuery("#foo").css("opacity", 1); jQuery("#foo").css("opacity", 1);
equals( jQuery("#foo").css("filter"), filterVal2, "Setting opacity in IE doesn't duplicate opacity filter" ); equal( jQuery("#foo").css("filter"), filterVal2, "Setting opacity in IE doesn't duplicate opacity filter" );
equals( jQuery("#foo").css("opacity"), 1, "Setting opacity in IE with other filters works" ); equal( jQuery("#foo").css("opacity"), 1, "Setting opacity in IE with other filters works" );
jQuery("#foo").css("filter", filterVal3).css("opacity", 1); jQuery("#foo").css("filter", filterVal3).css("opacity", 1);
ok( jQuery("#foo").css("filter").indexOf(filterVal3) !== -1, "Setting opacity in IE doesn't clobber other filters" ); ok( jQuery("#foo").css("filter").indexOf(filterVal3) !== -1, "Setting opacity in IE doesn't clobber other filters" );
}); });
...@@ -310,7 +310,7 @@ test("css(String, Function)", function() { ...@@ -310,7 +310,7 @@ test("css(String, Function)", function() {
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]
equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize ); equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++; index++;
}); });
...@@ -339,7 +339,7 @@ test("css(String, Function) with incoming value", function() { ...@@ -339,7 +339,7 @@ test("css(String, Function) with incoming value", function() {
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]
equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize ); equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++; index++;
return computedSize; return computedSize;
}); });
...@@ -370,7 +370,7 @@ test("css(Object) where values are Functions", function() { ...@@ -370,7 +370,7 @@ test("css(Object) where values are Functions", function() {
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]
equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize ); equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++; index++;
}); });
...@@ -399,7 +399,7 @@ test("css(Object) where values are Functions with incoming values", function() { ...@@ -399,7 +399,7 @@ test("css(Object) where values are Functions with incoming values", function() {
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]
equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize ); equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++; index++;
return computedSize; return computedSize;
}}); }});
...@@ -423,13 +423,13 @@ test(":visible selector works properly on table elements (bug #4512)", function ...@@ -423,13 +423,13 @@ test(":visible selector works properly on table elements (bug #4512)", function
expect(1); expect(1);
jQuery("#table").html("<tr><td style='display:none'>cell</td><td>cell</td></tr>"); jQuery("#table").html("<tr><td style='display:none'>cell</td><td>cell</td></tr>");
equals(jQuery("#table td:visible").length, 1, "hidden cell is not perceived as visible"); equal(jQuery("#table td:visible").length, 1, "hidden cell is not perceived as visible");
}); });
test(":visible selector works properly on children with a hidden parent (bug #4512)", function () { test(":visible selector works properly on children with a hidden parent (bug #4512)", function () {
expect(1); expect(1);
jQuery("#table").css("display", "none").html("<tr><td>cell</td><td>cell</td></tr>"); jQuery("#table").css("display", "none").html("<tr><td>cell</td><td>cell</td></tr>");
equals(jQuery("#table td:visible").length, 0, "hidden cell children not perceived as visible"); equal(jQuery("#table td:visible").length, 0, "hidden cell children not perceived as visible");
}); });
test("internal ref to elem.runtimeStyle (bug #7608)", function () { test("internal ref to elem.runtimeStyle (bug #7608)", function () {
...@@ -454,7 +454,7 @@ test("marginRight computed style (bug #3333)", function() { ...@@ -454,7 +454,7 @@ test("marginRight computed style (bug #3333)", function() {
marginRight: 0 marginRight: 0
}); });
equals($div.css("marginRight"), "0px", "marginRight correctly calculated with a width and display block"); equal($div.css("marginRight"), "0px", "marginRight correctly calculated with a width and display block");
}); });
test("jQuery.cssProps behavior, (bug #8402)", function() { test("jQuery.cssProps behavior, (bug #8402)", function() {
......
...@@ -3,7 +3,7 @@ module("data", { teardown: moduleTeardown }); ...@@ -3,7 +3,7 @@ module("data", { teardown: moduleTeardown });
test("expando", function(){ test("expando", function(){
expect(1); expect(1);
equals("expando" in jQuery, true, "jQuery is exposing the expando"); equal("expando" in jQuery, true, "jQuery is exposing the expando");
}); });
function dataTests (elem) { function dataTests (elem) {
...@@ -18,26 +18,26 @@ function dataTests (elem) { ...@@ -18,26 +18,26 @@ function dataTests (elem) {
return cacheLength; return cacheLength;
} }
equals( 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); var dataObj = jQuery.data(elem);
equals( 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" );
strictEqual( jQuery.hasData(elem), false, "jQuery.hasData agrees no data exists even when an empty data obj exists" ); strictEqual( jQuery.hasData(elem), false, "jQuery.hasData agrees no data exists even when an empty data obj exists" );
dataObj.foo = "bar"; dataObj.foo = "bar";
equals( jQuery.data(elem, "foo"), "bar", "Data is readable by jQuery.data when set directly on a returned data object" ); equal( jQuery.data(elem, "foo"), "bar", "Data is readable by jQuery.data when set directly on a returned data object" );
strictEqual( jQuery.hasData(elem), true, "jQuery.hasData agrees data exists when data exists" ); strictEqual( jQuery.hasData(elem), true, "jQuery.hasData agrees data exists when data exists" );
jQuery.data(elem, "foo", "baz"); jQuery.data(elem, "foo", "baz");
equals( jQuery.data(elem, "foo"), "baz", "Data can be changed by jQuery.data" ); equal( jQuery.data(elem, "foo"), "baz", "Data can be changed by jQuery.data" );
equals( dataObj.foo, "baz", "Changes made through jQuery.data propagate to referenced data object" ); equal( dataObj.foo, "baz", "Changes made through jQuery.data propagate to referenced data object" );
jQuery.data(elem, "foo", undefined); jQuery.data(elem, "foo", undefined);
equals( jQuery.data(elem, "foo"), "baz", "Data is not unset by passing undefined to jQuery.data" ); equal( jQuery.data(elem, "foo"), "baz", "Data is not unset by passing undefined to jQuery.data" );
jQuery.data(elem, "foo", null); jQuery.data(elem, "foo", null);
strictEqual( jQuery.data(elem, "foo"), null, "Setting null using jQuery.data works OK" ); strictEqual( jQuery.data(elem, "foo"), null, "Setting null using jQuery.data works OK" );
...@@ -46,11 +46,11 @@ function dataTests (elem) { ...@@ -46,11 +46,11 @@ function dataTests (elem) {
jQuery.data(elem, { "bar" : "baz", "boom" : "bloz" }); jQuery.data(elem, { "bar" : "baz", "boom" : "bloz" });
strictEqual( jQuery.data(elem, "foo"), "foo1", "Passing an object extends the data object instead of replacing it" ); strictEqual( jQuery.data(elem, "foo"), "foo1", "Passing an object extends the data object instead of replacing it" );
equals( jQuery.data(elem, "boom"), "bloz", "Extending the data object works" ); equal( jQuery.data(elem, "boom"), "bloz", "Extending the data object works" );
jQuery._data(elem, "foo", "foo2"); jQuery._data(elem, "foo", "foo2");
equals( jQuery._data(elem, "foo"), "foo2", "Setting internal data works" ); equal( jQuery._data(elem, "foo"), "foo2", "Setting internal data works" );
equals( 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 ); var internalDataObj = jQuery._data( elem );
ok( internalDataObj, "Internal data object exists" ); ok( internalDataObj, "Internal data object exists" );
...@@ -73,7 +73,7 @@ function dataTests (elem) { ...@@ -73,7 +73,7 @@ function dataTests (elem) {
strictEqual( jQuery.hasData(elem), true, "jQuery.hasData shows data exists even if it is only internal data" ); strictEqual( jQuery.hasData(elem), true, "jQuery.hasData shows data exists even if it is only internal data" );
jQuery.data(elem, "foo", "foo1"); jQuery.data(elem, "foo", "foo1");
equals( jQuery._data(elem, "foo"), "foo2", "Setting user data does not override internal data" ); equal( jQuery._data(elem, "foo"), "foo2", "Setting user data does not override internal data" );
// delete the last private data key so we can test removing public data // delete the last private data key so we can test removing public data
// will destroy the cache // will destroy the cache
...@@ -83,7 +83,7 @@ function dataTests (elem) { ...@@ -83,7 +83,7 @@ function dataTests (elem) {
var oldCacheLength = getCacheLength(); var oldCacheLength = getCacheLength();
jQuery.removeData(elem, "foo"); jQuery.removeData(elem, "foo");
equals( 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");
...@@ -98,29 +98,29 @@ function dataTests (elem) { ...@@ -98,29 +98,29 @@ function dataTests (elem) {
actual = elem[ jQuery.expando ]; actual = elem[ jQuery.expando ];
} }
equals( actual, expected, "Removing the last item in the data object destroys it" ); equal( actual, expected, "Removing the last item in the data object destroys it" );
} }
jQuery.data(elem, "foo", "foo1"); jQuery.data(elem, "foo", "foo1");
jQuery._data(elem, "foo", "foo2"); jQuery._data(elem, "foo", "foo2");
equals( jQuery.data(elem, "foo"), "foo1", "(sanity check) Ensure data is set in user data object" ); equal( jQuery.data(elem, "foo"), "foo1", "(sanity check) Ensure data is set in user data object" );
equals( jQuery._data(elem, "foo"), "foo2", "(sanity check) Ensure data is set in internal data object" ); equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) Ensure data is set in internal data object" );
jQuery.removeData(elem, "foo", true); jQuery.removeData(elem, "foo", true);
strictEqual( jQuery.data(elem, jQuery.expando), undefined, "Removing the last item in internal data destroys the internal data object" ); strictEqual( jQuery.data(elem, jQuery.expando), undefined, "Removing the last item in internal data destroys the internal data object" );
jQuery._data(elem, "foo", "foo2"); jQuery._data(elem, "foo", "foo2");
equals( jQuery._data(elem, "foo"), "foo2", "(sanity check) Ensure data is set in internal data object" ); equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) Ensure data is set in internal data object" );
jQuery.removeData(elem, "foo"); jQuery.removeData(elem, "foo");
equals( 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);
equals( 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" );
} }
else { else {
jQuery.removeData(elem, "foo", true); jQuery.removeData(elem, "foo", true);
...@@ -134,7 +134,7 @@ function dataTests (elem) { ...@@ -134,7 +134,7 @@ function dataTests (elem) {
actual = elem[ jQuery.expando ]; actual = elem[ jQuery.expando ];
} }
equals( actual, expected, "Removing the last item in the internal data object also destroys the user data object when it is empty" ); equal( actual, expected, "Removing the last item in the internal data object also destroys the user data object when it is empty" );
} }
} }
...@@ -187,11 +187,11 @@ test(".data()", function() { ...@@ -187,11 +187,11 @@ test(".data()", function() {
// TODO: Remove this hack which was introduced in 1.5.1 // TODO: Remove this hack which was introduced in 1.5.1
delete dataObj.toJSON; delete dataObj.toJSON;
same( dataObj, {test: "success"}, "data() get the entire data object" ); deepEqual( dataObj, {test: "success"}, "data() get the entire data object" );
strictEqual( div.data("foo"), undefined, "Make sure that missing result is still undefined" ); strictEqual( div.data("foo"), undefined, "Make sure that missing result is still undefined" );
var nodiv = jQuery("#unfound"); var nodiv = jQuery("#unfound");
equals( nodiv.data(), null, "data() on empty set returns null" ); equal( nodiv.data(), null, "data() on empty set returns null" );
var obj = { foo: "bar" }; var obj = { foo: "bar" };
jQuery(obj).data("foo", "baz"); jQuery(obj).data("foo", "baz");
...@@ -217,13 +217,13 @@ test(".data(String) and .data(String, Object)", function() { ...@@ -217,13 +217,13 @@ test(".data(String) and .data(String, Object)", function() {
ok( div.data("test") === undefined, "Check for no data exists" ); ok( div.data("test") === undefined, "Check for no data exists" );
div.data("test", "success"); div.data("test", "success");
equals( div.data("test"), "success", "Check for added data" ); equal( div.data("test"), "success", "Check for added data" );
div.data("test", "overwritten"); div.data("test", "overwritten");
equals( div.data("test"), "overwritten", "Check for overwritten data" ); equal( div.data("test"), "overwritten", "Check for overwritten data" );
div.data("test", undefined); div.data("test", undefined);
equals( div.data("test"), "overwritten", "Check that data wasn't removed"); equal( div.data("test"), "overwritten", "Check that data wasn't removed");
div.data("test", null); div.data("test", null);
ok( div.data("test") === null, "Check for null data"); ok( div.data("test") === null, "Check for null data");
...@@ -252,13 +252,13 @@ test(".data(String) and .data(String, Object)", function() { ...@@ -252,13 +252,13 @@ test(".data(String) and .data(String, Object)", function() {
.bind("getData.foo",function(e,key){ gets[key] += 3; }); .bind("getData.foo",function(e,key){ gets[key] += 3; });
div.data("test.foo", 2); div.data("test.foo", 2);
equals( div.data("test"), "overwritten", "Check for original data" ); equal( div.data("test"), "overwritten", "Check for original data" );
equals( div.data("test.foo"), 2, "Check for namespaced data" ); equal( div.data("test.foo"), 2, "Check for namespaced data" );
equals( div.data("test.bar"), "overwritten", "Check for unmatched namespace" ); equal( div.data("test.bar"), "overwritten", "Check for unmatched namespace" );
equals( hits.test, 2, "Check triggered setter functions" ); equal( hits.test, 2, "Check triggered setter functions" );
equals( gets.test, 5, "Check triggered getter functions" ); equal( gets.test, 5, "Check triggered getter functions" );
equals( changes.test, 2, "Check sets raise changeData"); equal( changes.test, 2, "Check sets raise changeData");
equals( changes.value, 2, "Check changeData after data has been set" ); equal( changes.value, 2, "Check changeData after data has been set" );
hits.test = 0; hits.test = 0;
gets.test = 0; gets.test = 0;
...@@ -266,29 +266,29 @@ test(".data(String) and .data(String, Object)", function() { ...@@ -266,29 +266,29 @@ test(".data(String) and .data(String, Object)", function() {
changes.value = null; changes.value = null;
div.data("test", 1); div.data("test", 1);
equals( div.data("test"), 1, "Check for original data" ); equal( div.data("test"), 1, "Check for original data" );
equals( div.data("test.foo"), 2, "Check for namespaced data" ); equal( div.data("test.foo"), 2, "Check for namespaced data" );
equals( div.data("test.bar"), 1, "Check for unmatched namespace" ); equal( div.data("test.bar"), 1, "Check for unmatched namespace" );
equals( hits.test, 1, "Check triggered setter functions" ); equal( hits.test, 1, "Check triggered setter functions" );
equals( gets.test, 5, "Check triggered getter functions" ); equal( gets.test, 5, "Check triggered getter functions" );
equals( changes.test, 1, "Check sets raise changeData" ); equal( changes.test, 1, "Check sets raise changeData" );
equals( changes.value, 1, "Check changeData after data has been set" ); equal( changes.value, 1, "Check changeData after data has been set" );
div div
.bind("getData",function(e,key){ return key + "root"; }) .bind("getData",function(e,key){ return key + "root"; })
.bind("getData.foo",function(e,key){ return key + "foo"; }); .bind("getData.foo",function(e,key){ return key + "foo"; });
equals( div.data("test"), "testroot", "Check for original data" ); equal( div.data("test"), "testroot", "Check for original data" );
equals( div.data("test.foo"), "testfoo", "Check for namespaced data" ); equal( div.data("test.foo"), "testfoo", "Check for namespaced data" );
equals( div.data("test.bar"), "testroot", "Check for unmatched namespace" ); equal( div.data("test.bar"), "testroot", "Check for unmatched namespace" );
// #3748 // #3748
var $elem = jQuery({exists:true}); var $elem = jQuery({exists:true});
equals( $elem.data("nothing"), undefined, "Non-existent data returns undefined"); equal( $elem.data("nothing"), undefined, "Non-existent data returns undefined");
equals( $elem.data("null", null).data("null"), null, "null's are preserved"); equal( $elem.data("null", null).data("null"), null, "null's are preserved");
equals( $elem.data("emptyString", "").data("emptyString"), "", "Empty strings are preserved"); equal( $elem.data("emptyString", "").data("emptyString"), "", "Empty strings are preserved");
equals( $elem.data("false", false).data("false"), false, "false's are preserved"); equal( $elem.data("false", false).data("false"), false, "false's are preserved");
equals( $elem.data("exists"), undefined, "Existing data is not returned" ); equal( $elem.data("exists"), undefined, "Existing data is not returned" );
// Clean up // Clean up
$elem.removeData(); $elem.removeData();
...@@ -304,27 +304,27 @@ test("data-* attributes", function() { ...@@ -304,27 +304,27 @@ test("data-* attributes", function() {
child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>"), child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>"),
dummy = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>"); dummy = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>");
equals( div.data("attr"), undefined, "Check for non-existing data-attr attribute" ); equal( div.data("attr"), undefined, "Check for non-existing data-attr attribute" );
div.attr("data-attr", "exists"); div.attr("data-attr", "exists");
equals( div.data("attr"), "exists", "Check for existing data-attr attribute" ); equal( div.data("attr"), "exists", "Check for existing data-attr attribute" );
div.attr("data-attr", "exists2"); div.attr("data-attr", "exists2");
equals( div.data("attr"), "exists", "Check that updates to data- don't update .data()" ); equal( div.data("attr"), "exists", "Check that updates to data- don't update .data()" );
div.data("attr", "internal").attr("data-attr", "external"); div.data("attr", "internal").attr("data-attr", "external");
equals( div.data("attr"), "internal", "Check for .data('attr') precedence (internal > external data-* attribute)" ); equal( div.data("attr"), "internal", "Check for .data('attr') precedence (internal > external data-* attribute)" );
div.remove(); div.remove();
child.appendTo("#qunit-fixture"); child.appendTo("#qunit-fixture");
equals( child.data("myobj"), "old data", "Value accessed from data-* attribute"); equal( child.data("myobj"), "old data", "Value accessed from data-* attribute");
child.data("myobj", "replaced"); child.data("myobj", "replaced");
equals( child.data("myobj"), "replaced", "Original data overwritten"); equal( child.data("myobj"), "replaced", "Original data overwritten");
child.data("ignored", "cache"); child.data("ignored", "cache");
equals( 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 obj = child.data(), obj2 = dummy.data(), check = [ "myobj", "ignored", "other" ], num = 0, num2 = 0;
...@@ -339,17 +339,17 @@ test("data-* attributes", function() { ...@@ -339,17 +339,17 @@ test("data-* attributes", function() {
num++; num++;
} }
equals( 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 ( var prop in obj2 ) {
num2++; num2++;
} }
equals( num2, check.length, "Make sure that the right number of properties came through." ); equal( num2, check.length, "Make sure that the right number of properties came through." );
child.attr("data-other", "newvalue"); child.attr("data-other", "newvalue");
equals( child.data("other"), "test", "Make sure value was pulled in properly from a .data()." ); equal( child.data("other"), "test", "Make sure value was pulled in properly from a .data()." );
child child
.attr("data-true", "true") .attr("data-true", "true")
...@@ -386,20 +386,20 @@ test("data-* attributes", function() { ...@@ -386,20 +386,20 @@ test("data-* attributes", function() {
function testData(index, elem) { function testData(index, elem) {
switch (index) { switch (index) {
case 0: case 0:
equals(jQuery(elem).data("foo"), "bar", "Check foo property"); equal(jQuery(elem).data("foo"), "bar", "Check foo property");
equals(jQuery(elem).data("bar"), "baz", "Check baz property"); equal(jQuery(elem).data("bar"), "baz", "Check baz property");
break; break;
case 1: case 1:
equals(jQuery(elem).data("test"), "bar", "Check test property"); equal(jQuery(elem).data("test"), "bar", "Check test property");
equals(jQuery(elem).data("bar"), "baz", "Check bar property"); equal(jQuery(elem).data("bar"), "baz", "Check bar property");
break; break;
case 2: case 2:
equals(jQuery(elem).data("zoooo"), "bar", "Check zoooo property"); equal(jQuery(elem).data("zoooo"), "bar", "Check zoooo property");
same(jQuery(elem).data("bar"), {"test":"baz"}, "Check bar property"); deepEqual(jQuery(elem).data("bar"), {"test":"baz"}, "Check bar property");
break; break;
case 3: case 3:
equals(jQuery(elem).data("number"), true, "Check number property"); equal(jQuery(elem).data("number"), true, "Check number property");
same(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 ", data].join(""));
...@@ -419,15 +419,15 @@ test(".data(Object)", function() { ...@@ -419,15 +419,15 @@ test(".data(Object)", function() {
var div = jQuery("<div/>"); var div = jQuery("<div/>");
div.data({ "test": "in", "test2": "in2" }); div.data({ "test": "in", "test2": "in2" });
equals( div.data("test"), "in", "Verify setting an object in data" ); equal( div.data("test"), "in", "Verify setting an object in data" );
equals( div.data("test2"), "in2", "Verify setting an object in data" ); equal( div.data("test2"), "in2", "Verify setting an object in data" );
var obj = {test:"unset"}, var obj = {test:"unset"},
jqobj = jQuery(obj); jqobj = jQuery(obj);
jqobj.data("test", "unset"); jqobj.data("test", "unset");
jqobj.data({ "test": "in", "test2": "in2" }); jqobj.data({ "test": "in", "test2": "in2" });
equals( jQuery.data(obj).test, "in", "Verify setting an object on an object extends the data object" ); equal( jQuery.data(obj).test, "in", "Verify setting an object on an object extends the data object" );
equals( obj.test2, undefined, "Verify setting an object on an object does not extend the object" ); equal( obj.test2, undefined, "Verify setting an object on an object does not extend the object" );
// manually clean up detached elements // manually clean up detached elements
div.remove(); div.remove();
...@@ -438,7 +438,7 @@ test("jQuery.removeData", function() { ...@@ -438,7 +438,7 @@ test("jQuery.removeData", function() {
var div = jQuery("#foo")[0]; var div = jQuery("#foo")[0];
jQuery.data(div, "test", "testing"); jQuery.data(div, "test", "testing");
jQuery.removeData(div, "test"); jQuery.removeData(div, "test");
equals( jQuery.data(div, "test"), undefined, "Check removal of data" ); equal( jQuery.data(div, "test"), undefined, "Check removal of data" );
jQuery.data(div, "test2", "testing"); jQuery.data(div, "test2", "testing");
jQuery.removeData( div ); jQuery.removeData( div );
...@@ -469,9 +469,9 @@ test("jQuery.removeData", function() { ...@@ -469,9 +469,9 @@ test("jQuery.removeData", function() {
var obj = {}; var obj = {};
jQuery.data(obj, "test", "testing"); jQuery.data(obj, "test", "testing");
equals( jQuery(obj).data("test"), "testing", "verify data on plain object"); equal( jQuery(obj).data("test"), "testing", "verify data on plain object");
jQuery.removeData(obj, "test"); jQuery.removeData(obj, "test");
equals( jQuery.data(obj, "test"), undefined, "Check removal of data on plain object" ); equal( jQuery.data(obj, "test"), undefined, "Check removal of data on plain object" );
jQuery.data( window, "BAD", true ); jQuery.data( window, "BAD", true );
jQuery.removeData( window, "BAD" ); jQuery.removeData( window, "BAD" );
...@@ -483,20 +483,20 @@ test(".removeData()", function() { ...@@ -483,20 +483,20 @@ test(".removeData()", function() {
var div = jQuery("#foo"); var div = jQuery("#foo");
div.data("test", "testing"); div.data("test", "testing");
div.removeData("test"); div.removeData("test");
equals( div.data("test"), undefined, "Check removal of data" ); equal( div.data("test"), undefined, "Check removal of data" );
div.data("test", "testing"); div.data("test", "testing");
div.data("test.foo", "testing2"); div.data("test.foo", "testing2");
div.removeData("test.bar"); div.removeData("test.bar");
equals( div.data("test.foo"), "testing2", "Make sure data is intact" ); equal( div.data("test.foo"), "testing2", "Make sure data is intact" );
equals( div.data("test"), "testing", "Make sure data is intact" ); equal( div.data("test"), "testing", "Make sure data is intact" );
div.removeData("test"); div.removeData("test");
equals( div.data("test.foo"), "testing2", "Make sure data is intact" ); equal( div.data("test.foo"), "testing2", "Make sure data is intact" );
equals( div.data("test"), undefined, "Make sure data is intact" ); equal( div.data("test"), undefined, "Make sure data is intact" );
div.removeData("test.foo"); div.removeData("test.foo");
equals( div.data("test.foo"), undefined, "Make sure data is intact" ); equal( div.data("test.foo"), undefined, "Make sure data is intact" );
}); });
if (window.JSON && window.JSON.stringify) { if (window.JSON && window.JSON.stringify) {
...@@ -506,7 +506,7 @@ if (window.JSON && window.JSON.stringify) { ...@@ -506,7 +506,7 @@ if (window.JSON && window.JSON.stringify) {
var obj = { foo: "bar" }; var obj = { foo: "bar" };
jQuery.data(obj, "hidden", true); jQuery.data(obj, "hidden", true);
equals( JSON.stringify(obj), "{\"foo\":\"bar\"}", "Expando is hidden from JSON.stringify" ); equal( JSON.stringify(obj), "{\"foo\":\"bar\"}", "Expando is hidden from JSON.stringify" );
}); });
} }
......
...@@ -351,18 +351,18 @@ test("jQuery.when - joined", function() { ...@@ -351,18 +351,18 @@ test("jQuery.when - joined", function() {
var promise = jQuery.when( defer1, defer2 ).done(function( a, b ) { var promise = jQuery.when( defer1, defer2 ).done(function( a, b ) {
if ( shouldResolve ) { if ( shouldResolve ) {
same( [ a, b ], expected, code + " => resolve" ); deepEqual( [ a, b ], expected, code + " => resolve" );
} else { } else {
ok( false , code + " => resolve" ); ok( false , code + " => resolve" );
} }
}).fail(function( a, b ) { }).fail(function( a, b ) {
if ( shouldError ) { if ( shouldError ) {
same( [ a, b ], expected, code + " => reject" ); deepEqual( [ a, b ], expected, code + " => reject" );
} else { } else {
ok( false , code + " => reject" ); ok( false , code + " => reject" );
} }
}).progress(function progress( a, b ) { }).progress(function progress( a, b ) {
same( [ a, b ], expectedNotify, code + " => progress" ); deepEqual( [ a, b ], expectedNotify, code + " => progress" );
}); });
} ); } );
} ); } );
......
...@@ -13,26 +13,26 @@ function testWidth( val ) { ...@@ -13,26 +13,26 @@ function testWidth( val ) {
var $div = jQuery("#nothiddendiv"); var $div = jQuery("#nothiddendiv");
$div.width( val(30) ); $div.width( val(30) );
equals($div.width(), 30, "Test set to 30 correctly"); equal($div.width(), 30, "Test set to 30 correctly");
$div.hide(); $div.hide();
equals($div.width(), 30, "Test hidden div"); equal($div.width(), 30, "Test hidden div");
$div.show(); $div.show();
$div.width( val(-1) ); // handle negative numbers by ignoring #1599 $div.width( val(-1) ); // handle negative numbers by ignoring #1599
equals($div.width(), 30, "Test negative width ignored"); equal($div.width(), 30, "Test negative width ignored");
$div.css("padding", "20px"); $div.css("padding", "20px");
equals($div.width(), 30, "Test padding specified with pixels"); equal($div.width(), 30, "Test padding specified with pixels");
$div.css("border", "2px solid #fff"); $div.css("border", "2px solid #fff");
equals($div.width(), 30, "Test border specified with pixels"); equal($div.width(), 30, "Test border specified with pixels");
$div.css({ display: "", border: "", padding: "" }); $div.css({ display: "", border: "", padding: "" });
jQuery("#nothiddendivchild").css({ width: 20, padding: "3px", border: "2px solid #fff" }); jQuery("#nothiddendivchild").css({ width: 20, padding: "3px", border: "2px solid #fff" });
equals(jQuery("#nothiddendivchild").width(), 20, "Test child width with border and padding"); equal(jQuery("#nothiddendivchild").width(), 20, "Test child width with border and padding");
jQuery("#nothiddendiv, #nothiddendivchild").css({ border: "", padding: "", width: "" }); jQuery("#nothiddendiv, #nothiddendivchild").css({ border: "", padding: "", width: "" });
var blah = jQuery("blah"); var blah = jQuery("blah");
equals( blah.width( val(10) ), blah, "Make sure that setting a width on an empty set returns the set." ); equal( blah.width( val(10) ), blah, "Make sure that setting a width on an empty set returns the set." );
equals( blah.width(), null, "Make sure 'null' is returned on an empty set"); equal( blah.width(), null, "Make sure 'null' is returned on an empty set");
jQuery.removeData($div[0], "olddisplay", true); jQuery.removeData($div[0], "olddisplay", true);
} }
...@@ -50,11 +50,11 @@ test("width() with function args", function() { ...@@ -50,11 +50,11 @@ test("width() with function args", function() {
var $div = jQuery("#nothiddendiv"); var $div = jQuery("#nothiddendiv");
$div.width( 30 ).width(function(i, width) { $div.width( 30 ).width(function(i, width) {
equals( width, 30, "Make sure previous value is corrrect." ); equal( width, 30, "Make sure previous value is corrrect." );
return width + 1; return width + 1;
}); });
equals( $div.width(), 31, "Make sure value was modified correctly." ); equal( $div.width(), 31, "Make sure value was modified correctly." );
}); });
function testHeight( val ) { function testHeight( val ) {
...@@ -62,26 +62,26 @@ function testHeight( val ) { ...@@ -62,26 +62,26 @@ function testHeight( val ) {
var $div = jQuery("#nothiddendiv"); var $div = jQuery("#nothiddendiv");
$div.height( val(30) ); $div.height( val(30) );
equals($div.height(), 30, "Test set to 30 correctly"); equal($div.height(), 30, "Test set to 30 correctly");
$div.hide(); $div.hide();
equals($div.height(), 30, "Test hidden div"); equal($div.height(), 30, "Test hidden div");
$div.show(); $div.show();
$div.height( val(-1) ); // handle negative numbers by ignoring #1599 $div.height( val(-1) ); // handle negative numbers by ignoring #1599
equals($div.height(), 30, "Test negative height ignored"); equal($div.height(), 30, "Test negative height ignored");
$div.css("padding", "20px"); $div.css("padding", "20px");
equals($div.height(), 30, "Test padding specified with pixels"); equal($div.height(), 30, "Test padding specified with pixels");
$div.css("border", "2px solid #fff"); $div.css("border", "2px solid #fff");
equals($div.height(), 30, "Test border specified with pixels"); equal($div.height(), 30, "Test border specified with pixels");
$div.css({ display: "", border: "", padding: "", height: "1px" }); $div.css({ display: "", border: "", padding: "", height: "1px" });
jQuery("#nothiddendivchild").css({ height: 20, padding: "3px", border: "2px solid #fff" }); jQuery("#nothiddendivchild").css({ height: 20, padding: "3px", border: "2px solid #fff" });
equals(jQuery("#nothiddendivchild").height(), 20, "Test child height with border and padding"); equal(jQuery("#nothiddendivchild").height(), 20, "Test child height with border and padding");
jQuery("#nothiddendiv, #nothiddendivchild").css({ border: "", padding: "", height: "" }); jQuery("#nothiddendiv, #nothiddendivchild").css({ border: "", padding: "", height: "" });
var blah = jQuery("blah"); var blah = jQuery("blah");
equals( blah.height( val(10) ), blah, "Make sure that setting a height on an empty set returns the set." ); equal( blah.height( val(10) ), blah, "Make sure that setting a height on an empty set returns the set." );
equals( blah.height(), null, "Make sure 'null' is returned on an empty set"); equal( blah.height(), null, "Make sure 'null' is returned on an empty set");
jQuery.removeData($div[0], "olddisplay", true); jQuery.removeData($div[0], "olddisplay", true);
} }
...@@ -99,11 +99,11 @@ test("height() with function args", function() { ...@@ -99,11 +99,11 @@ test("height() with function args", function() {
var $div = jQuery("#nothiddendiv"); var $div = jQuery("#nothiddendiv");
$div.height( 30 ).height(function(i, height) { $div.height( 30 ).height(function(i, height) {
equals( height, 30, "Make sure previous value is corrrect." ); equal( height, 30, "Make sure previous value is corrrect." );
return height + 1; return height + 1;
}); });
equals( $div.height(), 31, "Make sure value was modified correctly." ); equal( $div.height(), 31, "Make sure value was modified correctly." );
}); });
test("innerWidth()", function() { test("innerWidth()", function() {
...@@ -112,11 +112,11 @@ test("innerWidth()", function() { ...@@ -112,11 +112,11 @@ test("innerWidth()", function() {
var winWidth = jQuery( window ).width(), var winWidth = jQuery( window ).width(),
docWidth = jQuery( document ).width(); docWidth = jQuery( document ).width();
equals(jQuery(window).innerWidth(), winWidth, "Test on window without margin option"); equal(jQuery(window).innerWidth(), winWidth, "Test on window without margin option");
equals(jQuery(window).innerWidth(true), winWidth, "Test on window with margin option"); equal(jQuery(window).innerWidth(true), winWidth, "Test on window with margin option");
equals(jQuery(document).innerWidth(), docWidth, "Test on document without margin option"); equal(jQuery(document).innerWidth(), docWidth, "Test on document without margin option");
equals(jQuery(document).innerWidth(true), docWidth, "Test on document with margin option"); equal(jQuery(document).innerWidth(true), docWidth, "Test on document with margin option");
var $div = jQuery("#nothiddendiv"); var $div = jQuery("#nothiddendiv");
// set styles // set styles
...@@ -126,11 +126,11 @@ test("innerWidth()", function() { ...@@ -126,11 +126,11 @@ test("innerWidth()", function() {
width: 30 width: 30
}); });
equals($div.innerWidth(), 30, "Test with margin and border"); equal($div.innerWidth(), 30, "Test with margin and border");
$div.css("padding", "20px"); $div.css("padding", "20px");
equals($div.innerWidth(), 70, "Test with margin, border and padding"); equal($div.innerWidth(), 70, "Test with margin, border and padding");
$div.hide(); $div.hide();
equals($div.innerWidth(), 70, "Test hidden div"); equal($div.innerWidth(), 70, "Test hidden div");
// reset styles // reset styles
$div.css({ display: "", border: "", padding: "", width: "", height: "" }); $div.css({ display: "", border: "", padding: "", width: "", height: "" });
...@@ -138,7 +138,7 @@ test("innerWidth()", function() { ...@@ -138,7 +138,7 @@ test("innerWidth()", function() {
var div = jQuery( "<div>" ); var div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto // Temporarily require 0 for backwards compat - should be auto
equals( div.innerWidth(), 0, "Make sure that disconnected nodes are handled." ); equal( div.innerWidth(), 0, "Make sure that disconnected nodes are handled." );
div.remove(); div.remove();
jQuery.removeData($div[0], "olddisplay", true); jQuery.removeData($div[0], "olddisplay", true);
...@@ -150,11 +150,11 @@ test("innerHeight()", function() { ...@@ -150,11 +150,11 @@ test("innerHeight()", function() {
var winHeight = jQuery( window ).height(), var winHeight = jQuery( window ).height(),
docHeight = jQuery( document ).height(); docHeight = jQuery( document ).height();
equals(jQuery(window).innerHeight(), winHeight, "Test on window without margin option"); equal(jQuery(window).innerHeight(), winHeight, "Test on window without margin option");
equals(jQuery(window).innerHeight(true), winHeight, "Test on window with margin option"); equal(jQuery(window).innerHeight(true), winHeight, "Test on window with margin option");
equals(jQuery(document).innerHeight(), docHeight, "Test on document without margin option"); equal(jQuery(document).innerHeight(), docHeight, "Test on document without margin option");
equals(jQuery(document).innerHeight(true), docHeight, "Test on document with margin option"); equal(jQuery(document).innerHeight(true), docHeight, "Test on document with margin option");
var $div = jQuery("#nothiddendiv"); var $div = jQuery("#nothiddendiv");
// set styles // set styles
...@@ -164,11 +164,11 @@ test("innerHeight()", function() { ...@@ -164,11 +164,11 @@ test("innerHeight()", function() {
height: 30 height: 30
}); });
equals($div.innerHeight(), 30, "Test with margin and border"); equal($div.innerHeight(), 30, "Test with margin and border");
$div.css("padding", "20px"); $div.css("padding", "20px");
equals($div.innerHeight(), 70, "Test with margin, border and padding"); equal($div.innerHeight(), 70, "Test with margin, border and padding");
$div.hide(); $div.hide();
equals($div.innerHeight(), 70, "Test hidden div"); equal($div.innerHeight(), 70, "Test hidden div");
// reset styles // reset styles
$div.css({ display: "", border: "", padding: "", width: "", height: "" }); $div.css({ display: "", border: "", padding: "", width: "", height: "" });
...@@ -176,7 +176,7 @@ test("innerHeight()", function() { ...@@ -176,7 +176,7 @@ test("innerHeight()", function() {
var div = jQuery( "<div>" ); var div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto // Temporarily require 0 for backwards compat - should be auto
equals( div.innerHeight(), 0, "Make sure that disconnected nodes are handled." ); equal( div.innerHeight(), 0, "Make sure that disconnected nodes are handled." );
div.remove(); div.remove();
jQuery.removeData($div[0], "olddisplay", true); jQuery.removeData($div[0], "olddisplay", true);
...@@ -196,17 +196,17 @@ test("outerWidth()", function() { ...@@ -196,17 +196,17 @@ test("outerWidth()", function() {
var $div = jQuery("#nothiddendiv"); var $div = jQuery("#nothiddendiv");
$div.css("width", 30); $div.css("width", 30);
equals($div.outerWidth(), 30, "Test with only width set"); equal($div.outerWidth(), 30, "Test with only width set");
$div.css("padding", "20px"); $div.css("padding", "20px");
equals($div.outerWidth(), 70, "Test with padding"); equal($div.outerWidth(), 70, "Test with padding");
$div.css("border", "2px solid #fff"); $div.css("border", "2px solid #fff");
equals($div.outerWidth(), 74, "Test with padding and border"); equal($div.outerWidth(), 74, "Test with padding and border");
$div.css("margin", "10px"); $div.css("margin", "10px");
equals($div.outerWidth(), 74, "Test with padding, border and margin without margin option"); equal($div.outerWidth(), 74, "Test with padding, border and margin without margin option");
$div.css("position", "absolute"); $div.css("position", "absolute");
equals($div.outerWidth(true), 94, "Test with padding, border and margin with margin option"); equal($div.outerWidth(true), 94, "Test with padding, border and margin with margin option");
$div.hide(); $div.hide();
equals($div.outerWidth(true), 94, "Test hidden div with padding, border and margin with margin option"); equal($div.outerWidth(true), 94, "Test hidden div with padding, border and margin with margin option");
// reset styles // reset styles
$div.css({ position: "", display: "", border: "", padding: "", width: "", height: "" }); $div.css({ position: "", display: "", border: "", padding: "", width: "", height: "" });
...@@ -214,7 +214,7 @@ test("outerWidth()", function() { ...@@ -214,7 +214,7 @@ test("outerWidth()", function() {
var div = jQuery( "<div>" ); var div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto // Temporarily require 0 for backwards compat - should be auto
equals( div.outerWidth(), 0, "Make sure that disconnected nodes are handled." ); equal( div.outerWidth(), 0, "Make sure that disconnected nodes are handled." );
div.remove(); div.remove();
jQuery.removeData($div[0], "olddisplay", true); jQuery.removeData($div[0], "olddisplay", true);
...@@ -230,15 +230,15 @@ test("child of a hidden elem has accurate inner/outer/Width()/Height() see #944 ...@@ -230,15 +230,15 @@ test("child of a hidden elem has accurate inner/outer/Width()/Height() see #944
$divNormal.appendTo("body"); $divNormal.appendTo("body");
// tests that child div of a hidden div works the same as a normal div // tests that child div of a hidden div works the same as a normal div
equals( $divChild.width(), $divNormal.width(), "child of a hidden element width() is wrong see #9441" ); equal( $divChild.width(), $divNormal.width(), "child of a hidden element width() is wrong see #9441" );
equals( $divChild.innerWidth(), $divNormal.innerWidth(), "child of a hidden element innerWidth() is wrong see #9441" ); equal( $divChild.innerWidth(), $divNormal.innerWidth(), "child of a hidden element innerWidth() is wrong see #9441" );
equals( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #9441" ); equal( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #9441" );
equals( $divChild.outerWidth(true), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #9300" ); equal( $divChild.outerWidth(true), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #9300" );
equals( $divChild.height(), $divNormal.height(), "child of a hidden element height() is wrong see #9441" ); equal( $divChild.height(), $divNormal.height(), "child of a hidden element height() is wrong see #9441" );
equals( $divChild.innerHeight(), $divNormal.innerHeight(), "child of a hidden element innerHeight() is wrong see #9441" ); equal( $divChild.innerHeight(), $divNormal.innerHeight(), "child of a hidden element innerHeight() is wrong see #9441" );
equals( $divChild.outerHeight(), $divNormal.outerHeight(), "child of a hidden element outerHeight() is wrong see #9441" ); equal( $divChild.outerHeight(), $divNormal.outerHeight(), "child of a hidden element outerHeight() is wrong see #9441" );
equals( $divChild.outerHeight(true), $divNormal.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see #9300" ); equal( $divChild.outerHeight(true), $divNormal.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see #9300" );
// teardown html // teardown html
$divHiddenParent.remove(); $divHiddenParent.remove();
...@@ -283,16 +283,16 @@ test("outerHeight()", function() { ...@@ -283,16 +283,16 @@ test("outerHeight()", function() {
var $div = jQuery("#nothiddendiv"); var $div = jQuery("#nothiddendiv");
$div.css("height", 30); $div.css("height", 30);
equals($div.outerHeight(), 30, "Test with only width set"); equal($div.outerHeight(), 30, "Test with only width set");
$div.css("padding", "20px"); $div.css("padding", "20px");
equals($div.outerHeight(), 70, "Test with padding"); equal($div.outerHeight(), 70, "Test with padding");
$div.css("border", "2px solid #fff"); $div.css("border", "2px solid #fff");
equals($div.outerHeight(), 74, "Test with padding and border"); equal($div.outerHeight(), 74, "Test with padding and border");
$div.css("margin", "10px"); $div.css("margin", "10px");
equals($div.outerHeight(), 74, "Test with padding, border and margin without margin option"); equal($div.outerHeight(), 74, "Test with padding, border and margin without margin option");
equals($div.outerHeight(true), 94, "Test with padding, border and margin with margin option"); equal($div.outerHeight(true), 94, "Test with padding, border and margin with margin option");
$div.hide(); $div.hide();
equals($div.outerHeight(true), 94, "Test hidden div with padding, border and margin with margin option"); equal($div.outerHeight(true), 94, "Test hidden div with padding, border and margin with margin option");
// reset styles // reset styles
$div.css({ display: "", border: "", padding: "", width: "", height: "" }); $div.css({ display: "", border: "", padding: "", width: "", height: "" });
...@@ -300,7 +300,7 @@ test("outerHeight()", function() { ...@@ -300,7 +300,7 @@ test("outerHeight()", function() {
var div = jQuery( "<div>" ); var div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto // Temporarily require 0 for backwards compat - should be auto
equals( div.outerHeight(), 0, "Make sure that disconnected nodes are handled." ); equal( div.outerHeight(), 0, "Make sure that disconnected nodes are handled." );
div.remove(); div.remove();
jQuery.removeData($div[0], "olddisplay", true); jQuery.removeData($div[0], "olddisplay", true);
......
...@@ -12,7 +12,7 @@ test("show()", function() { ...@@ -12,7 +12,7 @@ test("show()", function() {
hiddendiv.hide().show(); hiddendiv.hide().show();
equals( hiddendiv.css("display"), "block", "Make sure a pre-hidden div is visible." ); equal( hiddendiv.css("display"), "block", "Make sure a pre-hidden div is visible." );
var div = jQuery("<div>").hide().appendTo("#qunit-fixture").show(); var div = jQuery("<div>").hide().appendTo("#qunit-fixture").show();
...@@ -87,7 +87,7 @@ test("show()", function() { ...@@ -87,7 +87,7 @@ test("show()", function() {
jQuery.each(test, function(selector, expected) { jQuery.each(test, function(selector, expected) {
var elem = jQuery(selector, "#show-tests").show(); var elem = jQuery(selector, "#show-tests").show();
equals( elem.css("display"), expected, "Show using correct display type for " + selector ); equal( elem.css("display"), expected, "Show using correct display type for " + selector );
}); });
// Make sure that showing or hiding a text node doesn't cause an error // Make sure that showing or hiding a text node doesn't cause an error
...@@ -126,7 +126,7 @@ test("show(Number) - other displays", function() { ...@@ -126,7 +126,7 @@ test("show(Number) - other displays", function() {
jQuery.each(test, function(selector, expected) { jQuery.each(test, function(selector, expected) {
var elem = jQuery(selector, "#show-tests").show(1, function() { var elem = jQuery(selector, "#show-tests").show(1, function() {
equals( elem.css("display"), expected, "Show using correct display type for " + selector ); equal( elem.css("display"), expected, "Show using correct display type for " + selector );
if ( ++num === 15 ) { if ( ++num === 15 ) {
start(); start();
} }
...@@ -156,11 +156,11 @@ test("Persist correct display value", function() { ...@@ -156,11 +156,11 @@ test("Persist correct display value", function() {
$span.hide(); $span.hide();
$span.fadeIn(100, function() { $span.fadeIn(100, function() {
equals($span.css("display"), display, "Expecting display: " + display); equal($span.css("display"), display, "Expecting display: " + display);
$span.fadeOut(100, function () { $span.fadeOut(100, function () {
equals($span.css("display"), displayNone, "Expecting display: " + displayNone); equal($span.css("display"), displayNone, "Expecting display: " + displayNone);
$span.fadeIn(100, function() { $span.fadeIn(100, function() {
equals($span.css("display"), display, "Expecting display: " + display); equal($span.css("display"), display, "Expecting display: " + display);
start(); start();
}); });
}); });
...@@ -172,16 +172,16 @@ test("show() resolves correct default display #8099", function() { ...@@ -172,16 +172,16 @@ test("show() resolves correct default display #8099", function() {
var tt8099 = jQuery("<tt/>").appendTo("body"), var tt8099 = jQuery("<tt/>").appendTo("body"),
dfn8099 = jQuery("<dfn/>", { html: "foo"}).appendTo("body"); dfn8099 = jQuery("<dfn/>", { html: "foo"}).appendTo("body");
equals( tt8099.css("display"), "none", "default display override for all tt" ); equal( tt8099.css("display"), "none", "default display override for all tt" );
equals( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" ); equal( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" );
equals( jQuery("#foo").hide().show().css("display"), "block", "Correctly resolves display:block after hide/show" ); equal( jQuery("#foo").hide().show().css("display"), "block", "Correctly resolves display:block after hide/show" );
equals( tt8099.hide().css("display"), "none", "default display override for all tt" ); equal( tt8099.hide().css("display"), "none", "default display override for all tt" );
equals( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" ); equal( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" );
equals( dfn8099.css("display"), "none", "default display override for all dfn" ); equal( dfn8099.css("display"), "none", "default display override for all dfn" );
equals( dfn8099.show().css("display"), "inline", "Correctly resolves display:inline" ); equal( dfn8099.show().css("display"), "inline", "Correctly resolves display:inline" );
tt8099.remove(); tt8099.remove();
dfn8099.remove(); dfn8099.remove();
...@@ -195,7 +195,7 @@ test("animate(Hash, Object, Function)", function() { ...@@ -195,7 +195,7 @@ test("animate(Hash, Object, Function)", function() {
var hash = {opacity: "show"}; var hash = {opacity: "show"};
var hashCopy = jQuery.extend({}, hash); var hashCopy = jQuery.extend({}, hash);
jQuery("#foo").animate(hash, 0, function() { jQuery("#foo").animate(hash, 0, function() {
equals( hash.opacity, hashCopy.opacity, "Check if animate changed the hash parameter" ); equal( hash.opacity, hashCopy.opacity, "Check if animate changed the hash parameter" );
start(); start();
}); });
}); });
...@@ -204,7 +204,7 @@ test("animate negative height", function() { ...@@ -204,7 +204,7 @@ test("animate negative height", function() {
expect(1); expect(1);
stop(); stop();
jQuery("#foo").animate({ height: -100 }, 100, function() { jQuery("#foo").animate({ height: -100 }, 100, function() {
equals( this.offsetHeight, 0, "Verify height." ); equal( this.offsetHeight, 0, "Verify height." );
start(); start();
}); });
}); });
...@@ -221,9 +221,9 @@ test("animate block as inline width/height", function() { ...@@ -221,9 +221,9 @@ test("animate block as inline width/height", function() {
stop(); stop();
jQuery("#foo").css({ display: "inline", width: "", height: "" }).animate({ width: 42, height: 42 }, 100, function() { jQuery("#foo").css({ display: "inline", width: "", height: "" }).animate({ width: 42, height: 42 }, 100, function() {
equals( jQuery(this).css("display"), jQuery.support.inlineBlockNeedsLayout ? "inline" : "inline-block", "inline-block was set on non-floated inline element when animating width/height" ); equal( jQuery(this).css("display"), jQuery.support.inlineBlockNeedsLayout ? "inline" : "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
equals( this.offsetWidth, 42, "width was animated" ); equal( this.offsetWidth, 42, "width was animated" );
equals( this.offsetHeight, 42, "height was animated" ); equal( this.offsetHeight, 42, "height was animated" );
start(); start();
}); });
...@@ -249,9 +249,9 @@ test("animate native inline width/height", function() { ...@@ -249,9 +249,9 @@ test("animate native inline width/height", function() {
.append("<span>text</span>") .append("<span>text</span>")
.children("span") .children("span")
.animate({ width: 42, height: 42 }, 100, function() { .animate({ width: 42, height: 42 }, 100, function() {
equals( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" ); equal( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
equals( this.offsetWidth, 42, "width was animated" ); equal( this.offsetWidth, 42, "width was animated" );
equals( this.offsetHeight, 42, "height was animated" ); equal( this.offsetHeight, 42, "height was animated" );
start(); start();
}); });
...@@ -267,9 +267,9 @@ test("animate block width/height", function() { ...@@ -267,9 +267,9 @@ test("animate block width/height", function() {
expect(3); expect(3);
stop(); stop();
jQuery("#foo").css({ display: "block", width: 20, height: 20 }).animate({ width: 42, height: 42 }, 100, function() { jQuery("#foo").css({ display: "block", width: 20, height: 20 }).animate({ width: 42, height: 42 }, 100, function() {
equals( jQuery(this).css("display"), "block", "inline-block was not set on block element when animating width/height" ); equal( jQuery(this).css("display"), "block", "inline-block was not set on block element when animating width/height" );
equals( this.offsetWidth, 42, "width was animated" ); equal( this.offsetWidth, 42, "width was animated" );
equals( this.offsetHeight, 42, "height was animated" ); equal( this.offsetHeight, 42, "height was animated" );
start(); start();
}); });
}); });
...@@ -281,7 +281,7 @@ test("animate table width/height", function() { ...@@ -281,7 +281,7 @@ test("animate table width/height", function() {
var displayMode = jQuery("#table").css("display") !== "table" ? "block" : "table"; var displayMode = jQuery("#table").css("display") !== "table" ? "block" : "table";
jQuery("#table").animate({ width: 42, height: 42 }, 100, function() { jQuery("#table").animate({ width: 42, height: 42 }, 100, function() {
equals( jQuery(this).css("display"), displayMode, "display mode is correct" ); equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
start(); start();
}); });
}); });
...@@ -294,13 +294,13 @@ test("animate table-row width/height", function() { ...@@ -294,13 +294,13 @@ test("animate table-row width/height", function() {
.html("<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>") .html("<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
.find("tr"); .find("tr");
// IE<8 uses “block” instead of the correct display type // IE<8 uses "block" instead of the correct display type
var displayMode = tr.css("display") !== "table-row" ? "block" : "table-row"; var displayMode = tr.css("display") !== "table-row" ? "block" : "table-row";
tr.animate({ width: 10, height: 10 }, 100, function() { tr.animate({ width: 10, height: 10 }, 100, function() {
equals( jQuery(this).css("display"), displayMode, "display mode is correct" ); equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
equals( this.offsetWidth, 20, "width animated to shrink wrap point" ); equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
equals( this.offsetHeight, 20, "height animated to shrink wrap point" ); equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
start(); start();
}); });
}); });
...@@ -313,13 +313,13 @@ test("animate table-cell width/height", function() { ...@@ -313,13 +313,13 @@ test("animate table-cell width/height", function() {
.html("<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>") .html("<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
.find("td"); .find("td");
// IE<8 uses “block” instead of the correct display type // IE<8 uses "block" instead of the correct display type
var displayMode = td.css("display") !== "table-cell" ? "block" : "table-cell"; var displayMode = td.css("display") !== "table-cell" ? "block" : "table-cell";
td.animate({ width: 10, height: 10 }, 100, function() { td.animate({ width: 10, height: 10 }, 100, function() {
equals( jQuery(this).css("display"), displayMode, "display mode is correct" ); equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
equals( this.offsetWidth, 20, "width animated to shrink wrap point" ); equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
equals( this.offsetHeight, 20, "height animated to shrink wrap point" ); equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
start(); start();
}); });
}); });
...@@ -330,8 +330,8 @@ test("animate resets overflow-x and overflow-y when finished", function() { ...@@ -330,8 +330,8 @@ test("animate resets overflow-x and overflow-y when finished", function() {
jQuery("#foo") jQuery("#foo")
.css({ display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" }) .css({ display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" })
.animate({ width: 42, height: 42 }, 100, function() { .animate({ width: 42, height: 42 }, 100, function() {
equals( this.style.overflowX, "visible", "overflow-x is visible" ); equal( this.style.overflowX, "visible", "overflow-x is visible" );
equals( this.style.overflowY, "auto", "overflow-y is auto" ); equal( this.style.overflowY, "auto", "overflow-y is auto" );
start(); start();
}); });
}); });
...@@ -347,7 +347,7 @@ test("animate option (queue === false)", function () { ...@@ -347,7 +347,7 @@ test("animate option (queue === false)", function () {
$foo.animate({width:"100px"}, 3000, function () { $foo.animate({width:"100px"}, 3000, function () {
// should finish after unqueued animation so second // should finish after unqueued animation so second
order.push(2); order.push(2);
same( order, [ 1, 2 ], "Animations finished in the correct order" ); deepEqual( order, [ 1, 2 ], "Animations finished in the correct order" );
start(); start();
}); });
$foo.animate({fontSize:"2em"}, {queue:false, duration:10, complete:function () { $foo.animate({fontSize:"2em"}, {queue:false, duration:10, complete:function () {
...@@ -372,7 +372,7 @@ asyncTest( "animate option { queue: false }", function() { ...@@ -372,7 +372,7 @@ asyncTest( "animate option { queue: false }", function() {
} }
}); });
equals( foo.queue().length, 0, "Queue is empty" ); equal( foo.queue().length, 0, "Queue is empty" );
}); });
asyncTest( "animate option { queue: true }", function() { asyncTest( "animate option { queue: true }", function() {
...@@ -407,8 +407,8 @@ asyncTest( "animate option { queue: 'name' }", function() { ...@@ -407,8 +407,8 @@ asyncTest( "animate option { queue: 'name' }", function() {
// second callback function // second callback function
order.push( 2 ); order.push( 2 );
equals( foo.width(), origWidth + 100, "Animation ended" ); equal( foo.width(), origWidth + 100, "Animation ended" );
equals( foo.queue("name").length, 1, "Queue length of 'name' queue" ); equal( foo.queue("name").length, 1, "Queue length of 'name' queue" );
} }
}).queue( "name", function( next ) { }).queue( "name", function( next ) {
...@@ -421,8 +421,8 @@ asyncTest( "animate option { queue: 'name' }", function() { ...@@ -421,8 +421,8 @@ asyncTest( "animate option { queue: 'name' }", function() {
// this is the first callback function that should be called // this is the first callback function that should be called
order.push( 1 ); order.push( 1 );
equals( foo.width(), origWidth, "Animation does not start on its own." ); equal( foo.width(), origWidth, "Animation does not start on its own." );
equals( foo.queue("name").length, 2, "Queue length of 'name' queue" ); equal( foo.queue("name").length, 2, "Queue length of 'name' queue" );
foo.dequeue( "name" ); foo.dequeue( "name" );
}, 100 ); }, 100 );
...@@ -437,7 +437,7 @@ test("animate with no properties", function() { ...@@ -437,7 +437,7 @@ test("animate with no properties", function() {
count++; count++;
}); });
equals( divs.length, count, "Make sure that callback is called for each element in the set." ); equal( divs.length, count, "Make sure that callback is called for each element in the set." );
stop(); stop();
...@@ -457,7 +457,7 @@ test("animate duration 0", function() { ...@@ -457,7 +457,7 @@ test("animate duration 0", function() {
var $elems = jQuery([{ a:0 },{ a:0 }]), counter = 0; var $elems = jQuery([{ a:0 },{ a:0 }]), counter = 0;
equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" ); equal( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
$elems.eq(0).animate( {a:1}, 0, function(){ $elems.eq(0).animate( {a:1}, 0, function(){
ok( true, "Animate a simple property." ); ok( true, "Animate a simple property." );
...@@ -465,16 +465,16 @@ test("animate duration 0", function() { ...@@ -465,16 +465,16 @@ test("animate duration 0", function() {
}); });
// Failed until [6115] // Failed until [6115]
equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" ); equal( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
equals( counter, 1, "One synchronic animations" ); equal( counter, 1, "One synchronic animations" );
$elems.animate( { a:2 }, 0, function(){ $elems.animate( { a:2 }, 0, function(){
ok( true, "Animate a second simple property." ); ok( true, "Animate a second simple property." );
counter++; counter++;
}); });
equals( counter, 3, "Multiple synchronic animations" ); equal( counter, 3, "Multiple synchronic animations" );
$elems.eq(0).animate( {a:3}, 0, function(){ $elems.eq(0).animate( {a:3}, 0, function(){
ok( true, "Animate a third simple property." ); ok( true, "Animate a third simple property." );
...@@ -483,7 +483,7 @@ test("animate duration 0", function() { ...@@ -483,7 +483,7 @@ test("animate duration 0", function() {
$elems.eq(1).animate( {a:3}, 200, function(){ $elems.eq(1).animate( {a:3}, 200, function(){
counter++; counter++;
// Failed until [6115] // Failed until [6115]
equals( counter, 5, "One synchronic and one asynchronic" ); equal( counter, 5, "One synchronic and one asynchronic" );
start(); start();
}); });
...@@ -506,7 +506,7 @@ test("animate hyphenated properties", function() { ...@@ -506,7 +506,7 @@ test("animate hyphenated properties", function() {
jQuery("#foo") jQuery("#foo")
.css("font-size", 10) .css("font-size", 10)
.animate({"font-size": 20}, 200, function() { .animate({"font-size": 20}, 200, function() {
equals( this.style.fontSize, "20px", "The font-size property was animated." ); equal( this.style.fontSize, "20px", "The font-size property was animated." );
start(); start();
}); });
}); });
...@@ -518,7 +518,7 @@ test("animate non-element", function() { ...@@ -518,7 +518,7 @@ test("animate non-element", function() {
var obj = { test: 0 }; var obj = { test: 0 };
jQuery(obj).animate({test: 200}, 200, function(){ jQuery(obj).animate({test: 200}, 200, function(){
equals( obj.test, 200, "The custom property should be modified." ); equal( obj.test, 200, "The custom property should be modified." );
start(); start();
}); });
}); });
...@@ -543,7 +543,7 @@ test("stop()", function() { ...@@ -543,7 +543,7 @@ test("stop()", function() {
setTimeout(function() { setTimeout(function() {
$foo.removeData(); $foo.removeData();
$foo.removeData(undefined, true); $foo.removeData(undefined, true);
equals( nw, $foo.width(), "The animation didn't continue" ); equal( nw, $foo.width(), "The animation didn't continue" );
start(); start();
}, 100); }, 100);
}, 100); }, 100);
...@@ -574,7 +574,7 @@ test("stop() - several in queue", function() { ...@@ -574,7 +574,7 @@ test("stop() - several in queue", function() {
$foo.animate({ width: "hide" }, 1000); $foo.animate({ width: "hide" }, 1000);
$foo.animate({ width: "show" }, 1000); $foo.animate({ width: "show" }, 1000);
setTimeout(function(){ setTimeout(function(){
equals( $foo.queue().length, 3, "All 3 still in the queue" ); equal( $foo.queue().length, 3, "All 3 still in the queue" );
var nw = $foo.width(); var nw = $foo.width();
notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px"); notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
$foo.stop(); $foo.stop();
...@@ -606,9 +606,9 @@ test("stop(clearQueue)", function() { ...@@ -606,9 +606,9 @@ test("stop(clearQueue)", function() {
nw = $foo.width(); nw = $foo.width();
ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px"); ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
equals( $foo.queue().length, 0, "The animation queue was cleared" ); equal( $foo.queue().length, 0, "The animation queue was cleared" );
setTimeout(function(){ setTimeout(function(){
equals( nw, $foo.width(), "The animation didn't continue" ); equal( nw, $foo.width(), "The animation didn't continue" );
start(); start();
}, 100); }, 100);
}, 100); }, 100);
...@@ -633,11 +633,11 @@ test("stop(clearQueue, gotoEnd)", function() { ...@@ -633,11 +633,11 @@ test("stop(clearQueue, gotoEnd)", function() {
nw = $foo.width(); nw = $foo.width();
// Disabled, being flaky // Disabled, being flaky
//equals( nw, 1, "Stop() reset the animation" ); //equal( nw, 1, "Stop() reset the animation" );
setTimeout(function(){ setTimeout(function(){
// Disabled, being flaky // Disabled, being flaky
//equals( $foo.queue().length, 2, "The next animation continued" ); //equal( $foo.queue().length, 2, "The next animation continued" );
$foo.stop(true); $foo.stop(true);
start(); start();
}, 100); }, 100);
...@@ -655,8 +655,8 @@ asyncTest( "stop( queue, ..., ... ) - Stop single queues", function() { ...@@ -655,8 +655,8 @@ asyncTest( "stop( queue, ..., ... ) - Stop single queues", function() {
},{ },{
duration: 1000, duration: 1000,
complete: function() { complete: function() {
equals( foo.width(), 400, "Animation completed for standard queue" ); equal( foo.width(), 400, "Animation completed for standard queue" );
equals( foo.height(), saved, "Height was not changed after the second stop"); equal( foo.height(), saved, "Height was not changed after the second stop");
start(); start();
} }
}); });
...@@ -668,7 +668,7 @@ asyncTest( "stop( queue, ..., ... ) - Stop single queues", function() { ...@@ -668,7 +668,7 @@ asyncTest( "stop( queue, ..., ... ) - Stop single queues", function() {
queue: "height" queue: "height"
}).dequeue( "height" ).stop( "height", false, true ); }).dequeue( "height" ).stop( "height", false, true );
equals( foo.height(), 400, "Height was stopped with gotoEnd" ); equal( foo.height(), 400, "Height was stopped with gotoEnd" );
foo.animate({ foo.animate({
height: 200 height: 200
...@@ -699,8 +699,8 @@ test("toggle()", function() { ...@@ -699,8 +699,8 @@ test("toggle()", function() {
jQuery.checkOverflowDisplay = function(){ jQuery.checkOverflowDisplay = function(){
var o = jQuery.css( this, "overflow" ); var o = jQuery.css( this, "overflow" );
equals(o, "visible", "Overflow should be visible: " + o); equal(o, "visible", "Overflow should be visible: " + o);
equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with."); equal(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
start(); start();
}; };
...@@ -713,7 +713,7 @@ test( "jQuery.fx.prototype.cur()", 6, function() { ...@@ -713,7 +713,7 @@ test( "jQuery.fx.prototype.cur()", 6, function() {
marginBottom: "-11000px" marginBottom: "-11000px"
})[0]; })[0];
equals( equal(
( new jQuery.fx( div, {}, "color" ) ).cur(), ( new jQuery.fx( div, {}, "color" ) ).cur(),
jQuery.css( div, "color" ), jQuery.css( div, "color" ),
"Return the same value as jQuery.css for complex properties (bug #7912)" "Return the same value as jQuery.css for complex properties (bug #7912)"
...@@ -748,7 +748,7 @@ test( "jQuery.fx.prototype.cur()", 6, function() { ...@@ -748,7 +748,7 @@ test( "jQuery.fx.prototype.cur()", 6, function() {
"Return 0 when jQuery.css returns 'auto'" "Return 0 when jQuery.css returns 'auto'"
); );
equals( equal(
( new jQuery.fx( div, {}, "marginBottom" ) ).cur(), ( new jQuery.fx( div, {}, "marginBottom" ) ).cur(),
-11000, -11000,
"support negative values < -10000 (bug #7193)" "support negative values < -10000 (bug #7193)"
...@@ -875,7 +875,7 @@ jQuery.each({ ...@@ -875,7 +875,7 @@ jQuery.each({
elem = elem[ 0 ]; elem = elem[ 0 ];
if ( t_w == "show" ) { if ( t_w == "show" ) {
equals( elem.style.display, "block", "Showing, display should block: " + elem.style.display ); equal( elem.style.display, "block", "Showing, display should block: " + elem.style.display );
} }
if ( t_w == "hide" || t_w == "show" ) { if ( t_w == "hide" || t_w == "show" ) {
...@@ -903,21 +903,21 @@ jQuery.each({ ...@@ -903,21 +903,21 @@ jQuery.each({
} }
if ( t_o == "hide" || t_o == "show" ) { if ( t_o == "hide" || t_o == "show" ) {
equals( cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o ); equal( cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o );
} }
if ( t_w == "hide" ) { if ( t_w == "hide" ) {
equals( elem.style.display, "none", "Hiding, display should be none: " + elem.style.display ); equal( elem.style.display, "none", "Hiding, display should be none: " + elem.style.display );
} }
if ( t_o.constructor == Number ) { if ( t_o.constructor == Number ) {
equals( 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 ) {
equals( elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width ); equal( elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width );
var cur_w = jQuery.css( elem,"width" ); var cur_w = jQuery.css( elem,"width" );
...@@ -925,7 +925,7 @@ jQuery.each({ ...@@ -925,7 +925,7 @@ jQuery.each({
} }
if ( t_h.constructor == Number ) { if ( t_h.constructor == Number ) {
equals( elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height ); equal( elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height );
var cur_h = jQuery.css( elem,"height" ); var cur_h = jQuery.css( elem,"height" );
...@@ -939,7 +939,7 @@ jQuery.each({ ...@@ -939,7 +939,7 @@ jQuery.each({
if ( /Auto/.test( fn ) ) { if ( /Auto/.test( fn ) ) {
notEqual( jQuery.css( elem, "height" ), old_h, "Make sure height is auto." ); notEqual( jQuery.css( elem, "height" ), old_h, "Make sure height is auto." );
} else { } else {
equals( jQuery.css( elem, "height" ), old_h, "Make sure height is not auto." ); equal( jQuery.css( elem, "height" ), old_h, "Make sure height is not auto." );
} }
} }
...@@ -970,7 +970,7 @@ jQuery.checkState = function() { ...@@ -970,7 +970,7 @@ jQuery.checkState = function() {
var self = this; var self = this;
jQuery.each(this.save, function( c, v ) { jQuery.each(this.save, function( c, v ) {
var cur = self.style[ c ] || jQuery.css( self, c ); var cur = self.style[ c ] || jQuery.css( self, c );
equals( cur, v, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")"); equal( cur, v, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
}); });
// manually clean data on modified element // manually clean data on modified element
...@@ -1147,11 +1147,11 @@ test("hide hidden elements (bug #7141)", function() { ...@@ -1147,11 +1147,11 @@ test("hide hidden elements (bug #7141)", function() {
QUnit.reset(); QUnit.reset();
var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture"); var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
equals( div.css("display"), "none", "Element is hidden by default" ); equal( div.css("display"), "none", "Element is hidden by default" );
div.hide(); div.hide();
ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" ); ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
div.show(); div.show();
equals( div.css("display"), "block", "Show a double-hidden element" ); equal( div.css("display"), "block", "Show a double-hidden element" );
div.remove(); div.remove();
}); });
...@@ -1162,11 +1162,11 @@ test("hide hidden elements, with animation (bug #7141)", function() { ...@@ -1162,11 +1162,11 @@ test("hide hidden elements, with animation (bug #7141)", function() {
stop(); stop();
var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture"); var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
equals( div.css("display"), "none", "Element is hidden by default" ); equal( div.css("display"), "none", "Element is hidden by default" );
div.hide(1, function () { div.hide(1, function () {
ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" ); ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
div.show(1, function () { div.show(1, function () {
equals( div.css("display"), "block", "Show a double-hidden element" ); equal( div.css("display"), "block", "Show a double-hidden element" );
start(); start();
}); });
}); });
......
...@@ -55,7 +55,7 @@ test("Handler changes and .trigger() order", function() { ...@@ -55,7 +55,7 @@ test("Handler changes and .trigger() order", function() {
markup.find( "b" ).trigger( "click" ); markup.find( "b" ).trigger( "click" );
equals( path, "b p div div ", "Delivered all events" ); equal( path, "b p div div ", "Delivered all events" );
markup.remove(); markup.remove();
}); });
...@@ -64,7 +64,7 @@ test("bind(), with data", function() { ...@@ -64,7 +64,7 @@ test("bind(), with data", function() {
expect(4); expect(4);
var handler = function(event) { var handler = function(event) {
ok( event.data, "bind() with data, check passed data exists" ); ok( event.data, "bind() with data, check passed data exists" );
equals( event.data.foo, "bar", "bind() with data, Check value of passed data" ); equal( event.data.foo, "bar", "bind() with data, Check value of passed data" );
}; };
jQuery("#firstp").bind("click", {foo: "bar"}, handler).click().unbind("click", handler); jQuery("#firstp").bind("click", {foo: "bar"}, handler).click().unbind("click", handler);
...@@ -72,7 +72,7 @@ test("bind(), with data", function() { ...@@ -72,7 +72,7 @@ test("bind(), with data", function() {
var test = function(){}; var test = function(){};
var handler2 = function(event) { var handler2 = function(event) {
equals( event.data, test, "bind() with function data, Check value of passed data" ); equal( event.data, test, "bind() with function data, Check value of passed data" );
}; };
jQuery("#firstp").bind("click", test, handler2).click().unbind("click", handler2); jQuery("#firstp").bind("click", test, handler2).click().unbind("click", handler2);
}); });
...@@ -81,7 +81,7 @@ test("click(), with data", function() { ...@@ -81,7 +81,7 @@ test("click(), with data", function() {
expect(3); expect(3);
var handler = function(event) { var handler = function(event) {
ok( event.data, "bind() with data, check passed data exists" ); ok( event.data, "bind() with data, check passed data exists" );
equals( event.data.foo, "bar", "bind() with data, Check value of passed data" ); equal( event.data.foo, "bar", "bind() with data, Check value of passed data" );
}; };
jQuery("#firstp").click({foo: "bar"}, handler).click().unbind("click", handler); jQuery("#firstp").click({foo: "bar"}, handler).click().unbind("click", handler);
...@@ -92,9 +92,9 @@ test("bind(), with data, trigger with data", function() { ...@@ -92,9 +92,9 @@ test("bind(), with data, trigger with data", function() {
expect(4); expect(4);
var handler = function(event, data) { var handler = function(event, data) {
ok( event.data, "check passed data exists" ); ok( event.data, "check passed data exists" );
equals( event.data.foo, "bar", "Check value of passed data" ); equal( event.data.foo, "bar", "Check value of passed data" );
ok( data, "Check trigger data" ); ok( data, "Check trigger data" );
equals( data.bar, "foo", "Check value of trigger data" ); equal( data.bar, "foo", "Check value of trigger data" );
}; };
jQuery("#firstp").bind("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]).unbind("click", handler); jQuery("#firstp").bind("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]).unbind("click", handler);
}); });
...@@ -110,8 +110,8 @@ test("bind(), multiple events at once", function() { ...@@ -110,8 +110,8 @@ test("bind(), multiple events at once", function() {
mouseoverCounter += 1; mouseoverCounter += 1;
}; };
jQuery("#firstp").bind("click mouseover", handler).trigger("click").trigger("mouseover"); jQuery("#firstp").bind("click mouseover", handler).trigger("click").trigger("mouseover");
equals( clickCounter, 1, "bind() with multiple events at once" ); equal( clickCounter, 1, "bind() with multiple events at once" );
equals( mouseoverCounter, 1, "bind() with multiple events at once" ); equal( mouseoverCounter, 1, "bind() with multiple events at once" );
}); });
test("bind(), five events at once", function() { test("bind(), five events at once", function() {
...@@ -127,7 +127,7 @@ test("bind(), five events at once", function() { ...@@ -127,7 +127,7 @@ test("bind(), five events at once", function() {
.trigger("foo").trigger("bar") .trigger("foo").trigger("bar")
.trigger("baz"); .trigger("baz");
equals( count, 5, "bind() five events at once" ); equal( count, 5, "bind() five events at once" );
}); });
test("bind(), multiple events at once and namespaces", function() { test("bind(), multiple events at once and namespaces", function() {
...@@ -136,7 +136,7 @@ test("bind(), multiple events at once and namespaces", function() { ...@@ -136,7 +136,7 @@ test("bind(), multiple events at once and namespaces", function() {
var cur, obj = {}; var cur, obj = {};
var div = jQuery("<div/>").bind("focusin.a", function(e) { var div = jQuery("<div/>").bind("focusin.a", function(e) {
equals( e.type, cur, "Verify right single event was fired." ); equal( e.type, cur, "Verify right single event was fired." );
}); });
cur = "focusin"; cur = "focusin";
...@@ -146,8 +146,8 @@ test("bind(), multiple events at once and namespaces", function() { ...@@ -146,8 +146,8 @@ test("bind(), multiple events at once and namespaces", function() {
div.remove(); div.remove();
div = jQuery("<div/>").bind("click mouseover", obj, function(e) { div = jQuery("<div/>").bind("click mouseover", obj, function(e) {
equals( e.type, cur, "Verify right multi event was fired." ); equal( e.type, cur, "Verify right multi event was fired." );
equals( e.data, obj, "Make sure the data came in correctly." ); equal( e.data, obj, "Make sure the data came in correctly." );
}); });
cur = "click"; cur = "click";
...@@ -160,7 +160,7 @@ test("bind(), multiple events at once and namespaces", function() { ...@@ -160,7 +160,7 @@ test("bind(), multiple events at once and namespaces", function() {
div.remove(); div.remove();
div = jQuery("<div/>").bind("focusin.a focusout.b", function(e) { div = jQuery("<div/>").bind("focusin.a focusout.b", function(e) {
equals( e.type, cur, "Verify right multi event was fired." ); equal( e.type, cur, "Verify right multi event was fired." );
}); });
cur = "focusin"; cur = "focusin";
...@@ -184,9 +184,9 @@ test("bind(), namespace with special add", function() { ...@@ -184,9 +184,9 @@ test("bind(), namespace with special add", function() {
jQuery.event.special.test = { jQuery.event.special.test = {
_default: function(e, data) { _default: function(e, data) {
equals( this, document, "Make sure we're at the top of the chain." ); equal( this, document, "Make sure we're at the top of the chain." );
equals( e.type, "test", "And that we're still dealing with a test event." ); equal( e.type, "test", "And that we're still dealing with a test event." );
equals( e.target, div[0], "And that the target is correct." ); equal( e.target, div[0], "And that the target is correct." );
ok( data !== undefined , "And that trigger data was passed." ); ok( data !== undefined , "And that trigger data was passed." );
}, },
setup: function(){}, setup: function(){},
...@@ -207,12 +207,12 @@ test("bind(), namespace with special add", function() { ...@@ -207,12 +207,12 @@ test("bind(), namespace with special add", function() {
div.bind("test.a", {x: 1}, function(e) { div.bind("test.a", {x: 1}, function(e) {
ok( !!e.xyz, "Make sure that the data is getting passed through." ); ok( !!e.xyz, "Make sure that the data is getting passed through." );
equals( e.data.x, 1, "Make sure data is attached properly." ); equal( e.data.x, 1, "Make sure data is attached properly." );
}); });
div.bind("test.b", {x: 2}, function(e) { div.bind("test.b", {x: 2}, function(e) {
ok( !!e.xyz, "Make sure that the data is getting passed through." ); ok( !!e.xyz, "Make sure that the data is getting passed through." );
equals( e.data.x, 2, "Make sure data is attached properly." ); equal( e.data.x, 2, "Make sure data is attached properly." );
}); });
// Should trigger 5 // Should trigger 5
...@@ -281,12 +281,12 @@ test("bind/one/unbind(Object)", function(){ ...@@ -281,12 +281,12 @@ test("bind/one/unbind(Object)", function(){
trigger(); trigger();
equals( clickCounter, 3, "bind(Object)" ); equal( clickCounter, 3, "bind(Object)" );
equals( mouseoverCounter, 3, "bind(Object)" ); equal( mouseoverCounter, 3, "bind(Object)" );
trigger(); trigger();
equals( clickCounter, 4, "bind(Object)" ); equal( clickCounter, 4, "bind(Object)" );
equals( mouseoverCounter, 4, "bind(Object)" ); equal( mouseoverCounter, 4, "bind(Object)" );
jQuery("#firstp").unbind({ jQuery("#firstp").unbind({
click:handler, click:handler,
...@@ -294,8 +294,8 @@ test("bind/one/unbind(Object)", function(){ ...@@ -294,8 +294,8 @@ test("bind/one/unbind(Object)", function(){
}); });
trigger(); trigger();
equals( clickCounter, 4, "bind(Object)" ); equal( clickCounter, 4, "bind(Object)" );
equals( mouseoverCounter, 4, "bind(Object)" ); equal( mouseoverCounter, 4, "bind(Object)" );
}); });
test("live/die(Object), delegate/undelegate(String, Object)", function() { test("live/die(Object), delegate/undelegate(String, Object)", function() {
...@@ -321,20 +321,20 @@ test("live/die(Object), delegate/undelegate(String, Object)", function() { ...@@ -321,20 +321,20 @@ test("live/die(Object), delegate/undelegate(String, Object)", function() {
$p.delegate( "a", events, 2 ); $p.delegate( "a", events, 2 );
trigger(); trigger();
equals( clickCounter, 3, "live/delegate" ); equal( clickCounter, 3, "live/delegate" );
equals( mouseoverCounter, 3, "live/delegate" ); equal( mouseoverCounter, 3, "live/delegate" );
$p.undelegate( "a", events ); $p.undelegate( "a", events );
trigger(); trigger();
equals( clickCounter, 4, "undelegate" ); equal( clickCounter, 4, "undelegate" );
equals( mouseoverCounter, 4, "undelegate" ); equal( mouseoverCounter, 4, "undelegate" );
$a.die( events ); $a.die( events );
trigger(); trigger();
equals( clickCounter, 4, "die" ); equal( clickCounter, 4, "die" );
equals( mouseoverCounter, 4, "die" ); equal( mouseoverCounter, 4, "die" );
}); });
test("live/delegate immediate propagation", function() { test("live/delegate immediate propagation", function() {
...@@ -351,7 +351,7 @@ test("live/delegate immediate propagation", function() { ...@@ -351,7 +351,7 @@ test("live/delegate immediate propagation", function() {
lastClick = "click2"; lastClick = "click2";
}); });
$a.trigger( "click" ); $a.trigger( "click" );
equals( lastClick, "click1", "live stopImmediatePropagation" ); equal( lastClick, "click1", "live stopImmediatePropagation" );
$a.die( "click" ); $a.die( "click" );
lastClick = ""; lastClick = "";
...@@ -363,7 +363,7 @@ test("live/delegate immediate propagation", function() { ...@@ -363,7 +363,7 @@ test("live/delegate immediate propagation", function() {
lastClick = "click2"; lastClick = "click2";
}); });
$a.trigger( "click" ); $a.trigger( "click" );
equals( lastClick, "click1", "delegate stopImmediatePropagation" ); equal( lastClick, "click1", "delegate stopImmediatePropagation" );
$p.undelegate( "click" ); $p.undelegate( "click" );
}); });
...@@ -389,7 +389,7 @@ test("bind/delegate bubbling, isDefaultPrevented", function() { ...@@ -389,7 +389,7 @@ test("bind/delegate bubbling, isDefaultPrevented", function() {
var orig = e.originalEvent; var orig = e.originalEvent;
if ( typeof(orig.defaultPrevented) === "boolean" || typeof(orig.returnValue) === "boolean" || orig.getPreventDefault ) { if ( typeof(orig.defaultPrevented) === "boolean" || typeof(orig.returnValue) === "boolean" || orig.getPreventDefault ) {
equals( e.isDefaultPrevented(), true, "isDefaultPrevented true passed to bubbled event" ); equal( e.isDefaultPrevented(), true, "isDefaultPrevented true passed to bubbled event" );
} else { } else {
// Opera < 11 doesn't implement any interface we can use, so give it a pass // Opera < 11 doesn't implement any interface we can use, so give it a pass
...@@ -403,7 +403,7 @@ test("bind/delegate bubbling, isDefaultPrevented", function() { ...@@ -403,7 +403,7 @@ test("bind/delegate bubbling, isDefaultPrevented", function() {
// Let the default action occur // Let the default action occur
}); });
$main.delegate("#foo", "click", function(e) { $main.delegate("#foo", "click", function(e) {
equals( e.isDefaultPrevented(), false, "isDefaultPrevented false passed to bubbled event" ); equal( e.isDefaultPrevented(), false, "isDefaultPrevented false passed to bubbled event" );
}); });
fakeClick( $anchor2 ); fakeClick( $anchor2 );
$anchor2.unbind( "click" ); $anchor2.unbind( "click" );
...@@ -423,7 +423,7 @@ test("bind(), trigger change on select", function() { ...@@ -423,7 +423,7 @@ test("bind(), trigger change on select", function() {
expect(5); expect(5);
var counter = 0; var counter = 0;
function selectOnChange(event) { function selectOnChange(event) {
equals( 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);
...@@ -474,7 +474,7 @@ test("bind(), namespaced events, cloned events", 18, function() { ...@@ -474,7 +474,7 @@ test("bind(), namespaced events, cloned events", 18, function() {
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
jQuery("#nonnodes").contents().bind("tester", function () { jQuery("#nonnodes").contents().bind("tester", function () {
equals(this.nodeType, 1, "Check node,textnode,comment bind just does real nodes" ); equal(this.nodeType, 1, "Check node,textnode,comment bind just does real nodes" );
}).trigger("tester"); }).trigger("tester");
// Make sure events stick with appendTo'd elements (which are cloned) #2027 // Make sure events stick with appendTo'd elements (which are cloned) #2027
...@@ -495,7 +495,7 @@ test("bind(), multi-namespaced events", function() { ...@@ -495,7 +495,7 @@ test("bind(), multi-namespaced events", function() {
]; ];
function check(name, msg){ function check(name, msg){
same(name, order.shift(), msg); deepEqual(name, order.shift(), msg);
} }
jQuery("#firstp").bind("custom.test",function(e){ jQuery("#firstp").bind("custom.test",function(e){
...@@ -550,12 +550,12 @@ test("bind(), with same function", function() { ...@@ -550,12 +550,12 @@ test("bind(), with same function", function() {
jQuery("#liveHandlerOrder").bind("foo.bar", func).bind("foo.zar", func); jQuery("#liveHandlerOrder").bind("foo.bar", func).bind("foo.zar", func);
jQuery("#liveHandlerOrder").trigger("foo.bar"); jQuery("#liveHandlerOrder").trigger("foo.bar");
equals(count, 1, "Verify binding function with multiple namespaces." ); equal(count, 1, "Verify binding function with multiple namespaces." );
jQuery("#liveHandlerOrder").unbind("foo.bar", func).unbind("foo.zar", func); jQuery("#liveHandlerOrder").unbind("foo.bar", func).unbind("foo.zar", func);
jQuery("#liveHandlerOrder").trigger("foo.bar"); jQuery("#liveHandlerOrder").trigger("foo.bar");
equals(count, 1, "Verify that removing events still work." ); equal(count, 1, "Verify that removing events still work." );
}); });
test("bind(), make sure order is maintained", function() { test("bind(), make sure order is maintained", function() {
...@@ -573,7 +573,7 @@ test("bind(), make sure order is maintained", function() { ...@@ -573,7 +573,7 @@ test("bind(), make sure order is maintained", function() {
elem.trigger("click"); elem.trigger("click");
equals( log.join(","), check.join(","), "Make sure order was maintained." ); equal( log.join(","), check.join(","), "Make sure order was maintained." );
elem.unbind("click"); elem.unbind("click");
}); });
...@@ -583,11 +583,11 @@ test("bind(), with different this object", function() { ...@@ -583,11 +583,11 @@ test("bind(), with different this object", function() {
var thisObject = { myThis: true }, var thisObject = { myThis: true },
data = { myData: true }, data = { myData: true },
handler1 = function( event ) { handler1 = function( event ) {
equals( this, thisObject, "bind() with different this object" ); equal( this, thisObject, "bind() with different this object" );
}, },
handler2 = function( event ) { handler2 = function( event ) {
equals( this, thisObject, "bind() with different this object and data" ); equal( this, thisObject, "bind() with different this object and data" );
equals( event.data, data, "bind() with different this object and data" ); equal( event.data, data, "bind() with different this object and data" );
}; };
jQuery("#firstp") jQuery("#firstp")
...@@ -603,17 +603,17 @@ test("bind(name, false), unbind(name, false)", function() { ...@@ -603,17 +603,17 @@ test("bind(name, false), unbind(name, false)", function() {
var main = 0; var main = 0;
jQuery("#qunit-fixture").bind("click", function(e){ main++; }); jQuery("#qunit-fixture").bind("click", function(e){ main++; });
jQuery("#ap").trigger("click"); jQuery("#ap").trigger("click");
equals( main, 1, "Verify that the trigger happened correctly." ); equal( main, 1, "Verify that the trigger happened correctly." );
main = 0; main = 0;
jQuery("#ap").bind("click", false); jQuery("#ap").bind("click", false);
jQuery("#ap").trigger("click"); jQuery("#ap").trigger("click");
equals( main, 0, "Verify that no bubble happened." ); equal( main, 0, "Verify that no bubble happened." );
main = 0; main = 0;
jQuery("#ap").unbind("click", false); jQuery("#ap").unbind("click", false);
jQuery("#ap").trigger("click"); jQuery("#ap").trigger("click");
equals( main, 1, "Verify that the trigger happened correctly." ); equal( main, 1, "Verify that the trigger happened correctly." );
// manually clean up events from elements outside the fixture // manually clean up events from elements outside the fixture
jQuery("#qunit-fixture").unbind("click"); jQuery("#qunit-fixture").unbind("click");
...@@ -625,17 +625,17 @@ test("live(name, false), die(name, false)", function() { ...@@ -625,17 +625,17 @@ test("live(name, false), die(name, false)", function() {
var main = 0; var main = 0;
jQuery("#qunit-fixture").live("click", function(e){ main++; }); jQuery("#qunit-fixture").live("click", function(e){ main++; });
jQuery("#ap").trigger("click"); jQuery("#ap").trigger("click");
equals( main, 1, "Verify that the trigger happened correctly." ); equal( main, 1, "Verify that the trigger happened correctly." );
main = 0; main = 0;
jQuery("#ap").live("click", false); jQuery("#ap").live("click", false);
jQuery("#ap").trigger("click"); jQuery("#ap").trigger("click");
equals( main, 0, "Verify that no bubble happened." ); equal( main, 0, "Verify that no bubble happened." );
main = 0; main = 0;
jQuery("#ap").die("click", false); jQuery("#ap").die("click", false);
jQuery("#ap").trigger("click"); jQuery("#ap").trigger("click");
equals( main, 1, "Verify that the trigger happened correctly." ); equal( main, 1, "Verify that the trigger happened correctly." );
jQuery("#qunit-fixture").die("click"); jQuery("#qunit-fixture").die("click");
}); });
...@@ -646,17 +646,17 @@ test("delegate(selector, name, false), undelegate(selector, name, false)", funct ...@@ -646,17 +646,17 @@ test("delegate(selector, name, false), undelegate(selector, name, false)", funct
jQuery("#qunit-fixture").delegate("#ap", "click", function(e){ main++; }); jQuery("#qunit-fixture").delegate("#ap", "click", function(e){ main++; });
jQuery("#ap").trigger("click"); jQuery("#ap").trigger("click");
equals( main, 1, "Verify that the trigger happened correctly." ); equal( main, 1, "Verify that the trigger happened correctly." );
main = 0; main = 0;
jQuery("#ap").delegate("#groups", "click", false); jQuery("#ap").delegate("#groups", "click", false);
jQuery("#groups").trigger("click"); jQuery("#groups").trigger("click");
equals( main, 0, "Verify that no bubble happened." ); equal( main, 0, "Verify that no bubble happened." );
main = 0; main = 0;
jQuery("#ap").undelegate("#groups", "click", false); jQuery("#ap").undelegate("#groups", "click", false);
jQuery("#groups").trigger("click"); jQuery("#groups").trigger("click");
equals( main, 1, "Verify that the trigger happened correctly." ); equal( main, 1, "Verify that the trigger happened correctly." );
jQuery("#qunit-fixture").undelegate("#ap", "click"); jQuery("#qunit-fixture").undelegate("#ap", "click");
}); });
...@@ -682,9 +682,9 @@ test("bind()/trigger()/unbind() on plain object", function() { ...@@ -682,9 +682,9 @@ test("bind()/trigger()/unbind() on plain object", function() {
var events = jQuery._data(obj, "events"); var events = jQuery._data(obj, "events");
ok( events, "Object has events bound." ); ok( events, "Object has events bound." );
equals( obj.events, undefined, "Events object on plain objects is not events" ); equal( obj.events, undefined, "Events object on plain objects is not events" );
equals( obj.test, undefined, "Make sure that test event is not on the plain object." ); equal( obj.test, undefined, "Make sure that test event is not on the plain object." );
equals( obj.handle, undefined, "Make sure that the event handler is not on the plain object." ); equal( obj.handle, undefined, "Make sure that the event handler is not on the plain object." );
// Should trigger 1 // Should trigger 1
jQuery(obj).trigger("test"); jQuery(obj).trigger("test");
...@@ -699,7 +699,7 @@ test("bind()/trigger()/unbind() on plain object", function() { ...@@ -699,7 +699,7 @@ test("bind()/trigger()/unbind() on plain object", function() {
// Make sure it doesn't complain when no events are found // Make sure it doesn't complain when no events are found
jQuery(obj).unbind("test"); jQuery(obj).unbind("test");
equals( obj && obj[ jQuery.expando ] && equal( obj && obj[ jQuery.expando ] &&
obj[ jQuery.expando ][ jQuery.expando ] && obj[ jQuery.expando ][ jQuery.expando ] &&
obj[ jQuery.expando ][ jQuery.expando ].events, undefined, "Make sure events object is removed" ); obj[ jQuery.expando ][ jQuery.expando ].events, undefined, "Make sure events object is removed" );
}); });
...@@ -759,7 +759,7 @@ test("unbind(eventObject)", function() { ...@@ -759,7 +759,7 @@ test("unbind(eventObject)", function() {
function assert( expected ){ function assert( expected ){
num = 0; num = 0;
$elem.trigger("foo").triggerHandler("bar"); $elem.trigger("foo").triggerHandler("bar");
equals( num, expected, "Check the right handlers are triggered" ); equal( num, expected, "Check the right handlers are triggered" );
} }
$elem $elem
...@@ -803,7 +803,7 @@ test("hover() and hover pseudo-event", function() { ...@@ -803,7 +803,7 @@ test("hover() and hover pseudo-event", function() {
.unbind("mouseenter mouseleave", handler1) .unbind("mouseenter mouseleave", handler1)
.mouseenter().mouseleave(); .mouseenter().mouseleave();
equals( times, 4, "hover handlers fired" ); equal( times, 4, "hover handlers fired" );
var balance = 0; var balance = 0;
jQuery( "#firstp" ) jQuery( "#firstp" )
...@@ -821,7 +821,7 @@ test("hover() and hover pseudo-event", function() { ...@@ -821,7 +821,7 @@ test("hover() and hover pseudo-event", function() {
.unbind("hover") .unbind("hover")
.trigger("mouseenter"); .trigger("mouseenter");
equals( balance, 0, "hover pseudo-event" ); equal( balance, 0, "hover pseudo-event" );
}); });
test("mouseover triggers mouseenter", function() { test("mouseover triggers mouseenter", function() {
...@@ -833,7 +833,7 @@ test("mouseover triggers mouseenter", function() { ...@@ -833,7 +833,7 @@ test("mouseover triggers mouseenter", function() {
count++; count++;
}); });
elem.trigger("mouseover"); elem.trigger("mouseover");
equals(count, 1, "make sure mouseover triggers a mouseenter" ); equal(count, 1, "make sure mouseover triggers a mouseenter" );
elem.remove(); elem.remove();
}); });
...@@ -865,13 +865,13 @@ test("mouseenter, mouseleave don't catch exceptions", function() { ...@@ -865,13 +865,13 @@ test("mouseenter, mouseleave don't catch exceptions", function() {
try { try {
elem.mouseenter(); elem.mouseenter();
} catch (e) { } catch (e) {
equals( e, "an Exception", "mouseenter doesn't catch exceptions" ); equal( e, "an Exception", "mouseenter doesn't catch exceptions" );
} }
try { try {
elem.mouseleave(); elem.mouseleave();
} catch (e) { } catch (e) {
equals( e, "an Exception", "mouseleave doesn't catch exceptions" ); equal( e, "an Exception", "mouseleave doesn't catch exceptions" );
} }
}); });
...@@ -881,7 +881,7 @@ test("trigger() shortcuts", function() { ...@@ -881,7 +881,7 @@ test("trigger() shortcuts", function() {
var elem = jQuery("<li><a href='#'>Change location</a></li>").prependTo("#firstUL"); var elem = jQuery("<li><a href='#'>Change location</a></li>").prependTo("#firstUL");
elem.find("a").bind("click", function() { elem.find("a").bind("click", function() {
var close = jQuery("spanx", this); // same with jQuery(this).find("span"); var close = jQuery("spanx", this); // same with jQuery(this).find("span");
equals( close.length, 0, "Context element does not exist, length must be zero" ); equal( close.length, 0, "Context element does not exist, length must be zero" );
ok( !close[0], "Context element does not exist, direct access to element must return undefined" ); ok( !close[0], "Context element does not exist, direct access to element must return undefined" );
return false; return false;
}).click(); }).click();
...@@ -898,14 +898,14 @@ test("trigger() shortcuts", function() { ...@@ -898,14 +898,14 @@ test("trigger() shortcuts", function() {
counter++; counter++;
}; };
jQuery("#firstp").click(); jQuery("#firstp").click();
equals( counter, 1, "Check that click, triggers onclick event handler also" ); equal( counter, 1, "Check that click, triggers onclick event handler also" );
var clickCounter = 0; var clickCounter = 0;
jQuery("#simon1")[0].onclick = function(event) { jQuery("#simon1")[0].onclick = function(event) {
clickCounter++; clickCounter++;
}; };
jQuery("#simon1").click(); jQuery("#simon1").click();
equals( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" ); equal( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" );
elem = jQuery("<img />").load(function(){ elem = jQuery("<img />").load(function(){
ok( true, "Trigger the load event, using the shortcut .load() (#2819)"); ok( true, "Trigger the load event, using the shortcut .load() (#2819)");
...@@ -933,29 +933,29 @@ test("trigger() bubbling", function() { ...@@ -933,29 +933,29 @@ test("trigger() bubbling", function() {
jQuery("#ap").bind("click", function(){ ap++; return false; }); jQuery("#ap").bind("click", function(){ ap++; return false; });
jQuery("html").trigger("click"); jQuery("html").trigger("click");
equals( win, 1, "HTML bubble" ); equal( win, 1, "HTML bubble" );
equals( doc, 1, "HTML bubble" ); equal( doc, 1, "HTML bubble" );
equals( html, 1, "HTML bubble" ); equal( html, 1, "HTML bubble" );
jQuery("body").trigger("click"); jQuery("body").trigger("click");
equals( win, 2, "Body bubble" ); equal( win, 2, "Body bubble" );
equals( doc, 2, "Body bubble" ); equal( doc, 2, "Body bubble" );
equals( html, 2, "Body bubble" ); equal( html, 2, "Body bubble" );
equals( body, 1, "Body bubble" ); equal( body, 1, "Body bubble" );
jQuery("#qunit-fixture").trigger("click"); jQuery("#qunit-fixture").trigger("click");
equals( win, 3, "Main bubble" ); equal( win, 3, "Main bubble" );
equals( doc, 3, "Main bubble" ); equal( doc, 3, "Main bubble" );
equals( html, 3, "Main bubble" ); equal( html, 3, "Main bubble" );
equals( body, 2, "Main bubble" ); equal( body, 2, "Main bubble" );
equals( main, 1, "Main bubble" ); equal( main, 1, "Main bubble" );
jQuery("#ap").trigger("click"); jQuery("#ap").trigger("click");
equals( doc, 3, "ap bubble" ); equal( doc, 3, "ap bubble" );
equals( html, 3, "ap bubble" ); equal( html, 3, "ap bubble" );
equals( body, 2, "ap bubble" ); equal( body, 2, "ap bubble" );
equals( main, 1, "ap bubble" ); equal( main, 1, "ap bubble" );
equals( ap, 1, "ap bubble" ); equal( ap, 1, "ap bubble" );
// manually clean up events from elements outside the fixture // manually clean up events from elements outside the fixture
jQuery(document).unbind("click"); jQuery(document).unbind("click");
...@@ -966,10 +966,10 @@ test("trigger(type, [data], [fn])", function() { ...@@ -966,10 +966,10 @@ test("trigger(type, [data], [fn])", function() {
expect(16); expect(16);
var handler = function(event, a, b, c) { var handler = function(event, a, b, c) {
equals( event.type, "click", "check passed data" ); equal( event.type, "click", "check passed data" );
equals( a, 1, "check passed data" ); equal( a, 1, "check passed data" );
equals( b, "2", "check passed data" ); equal( b, "2", "check passed data" );
equals( c, "abc", "check passed data" ); equal( c, "abc", "check passed data" );
return "test"; return "test";
}; };
...@@ -1008,7 +1008,7 @@ test("trigger(type, [data], [fn])", function() { ...@@ -1008,7 +1008,7 @@ test("trigger(type, [data], [fn])", function() {
// Trigger only the handlers (no native) // Trigger only the handlers (no native)
// Triggers 5 // Triggers 5
equals( $elem.triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" ); equal( $elem.triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" );
var pass = true; var pass = true;
try { try {
...@@ -1060,28 +1060,28 @@ test("trigger(eventObject, [data], [fn])", function() { ...@@ -1060,28 +1060,28 @@ test("trigger(eventObject, [data], [fn])", function() {
var event = jQuery.Event("noNew"); var event = jQuery.Event("noNew");
ok( event != window, "Instantiate jQuery.Event without the 'new' keyword" ); ok( event != window, "Instantiate jQuery.Event without the 'new' keyword" );
equals( event.type, "noNew", "Verify its type" ); equal( event.type, "noNew", "Verify its type" );
equals( event.isDefaultPrevented(), false, "Verify isDefaultPrevented" ); equal( event.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
equals( event.isPropagationStopped(), false, "Verify isPropagationStopped" ); equal( event.isPropagationStopped(), false, "Verify isPropagationStopped" );
equals( event.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" ); equal( event.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" );
event.preventDefault(); event.preventDefault();
equals( event.isDefaultPrevented(), true, "Verify isDefaultPrevented" ); equal( event.isDefaultPrevented(), true, "Verify isDefaultPrevented" );
event.stopPropagation(); event.stopPropagation();
equals( 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();
equals( event.isPropagationStopped(), true, "Verify isPropagationStopped" ); equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
equals( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" ); equal( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" );
$parent.bind("foo",function(e){ $parent.bind("foo",function(e){
// Tries bubbling // Tries bubbling
equals( e.type, "foo", "Verify event type when passed passing an event object" ); equal( e.type, "foo", "Verify event type when passed passing an event object" );
equals( e.target.id, "child", "Verify event.target when passed passing an event object" ); equal( e.target.id, "child", "Verify event.target when passed passing an event object" );
equals( e.currentTarget.id, "par", "Verify event.currentTarget when passed passing an event object" ); equal( e.currentTarget.id, "par", "Verify event.currentTarget when passed passing an event object" );
equals( e.secret, "boo!", "Verify event object's custom attribute when passed passing an event object" ); equal( e.secret, "boo!", "Verify event object's custom attribute when passed passing an event object" );
}); });
// test with an event object // test with an event object
...@@ -1101,14 +1101,14 @@ test("trigger(eventObject, [data], [fn])", function() { ...@@ -1101,14 +1101,14 @@ test("trigger(eventObject, [data], [fn])", function() {
$parent.bind("foo", error ); $parent.bind("foo", error );
$child.bind("foo",function(e, a, b, c ){ $child.bind("foo",function(e, a, b, c ){
equals( arguments.length, 4, "Check arguments length"); equal( arguments.length, 4, "Check arguments length");
equals( a, 1, "Check first custom argument"); equal( a, 1, "Check first custom argument");
equals( b, 2, "Check second custom argument"); equal( b, 2, "Check second custom argument");
equals( c, 3, "Check third custom argument"); equal( c, 3, "Check third custom argument");
equals( e.isDefaultPrevented(), false, "Verify isDefaultPrevented" ); equal( e.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
equals( e.isPropagationStopped(), false, "Verify isPropagationStopped" ); equal( e.isPropagationStopped(), false, "Verify isPropagationStopped" );
equals( e.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" ); equal( e.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" );
// Skips both errors // Skips both errors
e.stopImmediatePropagation(); e.stopImmediatePropagation();
...@@ -1122,7 +1122,7 @@ test("trigger(eventObject, [data], [fn])", function() { ...@@ -1122,7 +1122,7 @@ test("trigger(eventObject, [data], [fn])", function() {
event = new jQuery.Event("foo"); event = new jQuery.Event("foo");
$child.trigger( event, [1,2,3] ).unbind(); $child.trigger( event, [1,2,3] ).unbind();
equals( event.result, "result", "Check event.result attribute"); equal( event.result, "result", "Check event.result attribute");
// Will error if it bubbles // Will error if it bubbles
$child.triggerHandler("foo"); $child.triggerHandler("foo");
...@@ -1184,11 +1184,11 @@ test("jQuery.Event.currentTarget", function(){ ...@@ -1184,11 +1184,11 @@ test("jQuery.Event.currentTarget", function(){
jQuery('<div><p><button>shiny</button></p></div>') jQuery('<div><p><button>shiny</button></p></div>')
.on( "click", "p", function( e ){ .on( "click", "p", function( e ){
equals( e.currentTarget, this, "Check delegated currentTarget on event" ); equal( e.currentTarget, this, "Check delegated currentTarget on event" );
}) })
.find( "button" ) .find( "button" )
.on( "click", function( e ){ .on( "click", function( e ){
equals( e.currentTarget, this, "Check currentTarget on event" ); equal( e.currentTarget, this, "Check currentTarget on event" );
}) })
.click() .click()
.off( "click" ) .off( "click" )
...@@ -1205,19 +1205,19 @@ test("toggle(Function, Function, ...)", function() { ...@@ -1205,19 +1205,19 @@ test("toggle(Function, Function, ...)", function() {
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();
equals( count, 1, "Check for toggle(fn, fn)" ); equal( count, 1, "Check for toggle(fn, fn)" );
jQuery("#firstp").toggle(function () { jQuery("#firstp").toggle(function () {
equals(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;
jQuery("#simon1").one("click", function() { jQuery("#simon1").one("click", function() {
ok( true, "Execute event only once" ); ok( true, "Execute event only once" );
jQuery(this).toggle(function() { jQuery(this).toggle(function() {
equals( first++, 0, "toggle(Function,Function) assigned from within one('xxx'), see #1054" ); equal( first++, 0, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
}, function() { }, function() {
equals( first, 1, "toggle(Function,Function) assigned from within one('xxx'), see #1054" ); equal( first, 1, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
}); });
return false; return false;
}).click().click().click(); }).click().click().click();
...@@ -1237,15 +1237,15 @@ test("toggle(Function, Function, ...)", function() { ...@@ -1237,15 +1237,15 @@ test("toggle(Function, Function, ...)", function() {
var $div = jQuery("<div>&nbsp;</div>").toggle( fns[0], fns[1], fns[2] ); var $div = jQuery("<div>&nbsp;</div>").toggle( fns[0], fns[1], fns[2] );
$div.click(); $div.click();
equals( turn, 1, "Trying toggle with 3 functions, attempt 1 yields 1"); equal( turn, 1, "Trying toggle with 3 functions, attempt 1 yields 1");
$div.click(); $div.click();
equals( turn, 2, "Trying toggle with 3 functions, attempt 2 yields 2"); equal( turn, 2, "Trying toggle with 3 functions, attempt 2 yields 2");
$div.click(); $div.click();
equals( turn, 3, "Trying toggle with 3 functions, attempt 3 yields 3"); equal( turn, 3, "Trying toggle with 3 functions, attempt 3 yields 3");
$div.click(); $div.click();
equals( turn, 1, "Trying toggle with 3 functions, attempt 4 yields 1"); equal( turn, 1, "Trying toggle with 3 functions, attempt 4 yields 1");
$div.click(); $div.click();
equals( turn, 2, "Trying toggle with 3 functions, attempt 5 yields 2"); equal( turn, 2, "Trying toggle with 3 functions, attempt 5 yields 2");
$div.unbind("click",fns[0]); $div.unbind("click",fns[0]);
var data = jQuery._data( $div[0], "events" ); var data = jQuery._data( $div[0], "events" );
...@@ -1259,16 +1259,16 @@ test("toggle(Function, Function, ...)", function() { ...@@ -1259,16 +1259,16 @@ test("toggle(Function, Function, ...)", function() {
$div = jQuery("<div/>"); $div = jQuery("<div/>");
$div.toggle(function(){ a.push(1); }, function(){ a.push(2); }); $div.toggle(function(){ a.push(1); }, function(){ a.push(2); });
$div.click(); $div.click();
same( a, [1], "Check that a click worked." ); deepEqual( a, [1], "Check that a click worked." );
$div.toggle(function(){ b.push(1); }, function(){ b.push(2); }); $div.toggle(function(){ b.push(1); }, function(){ b.push(2); });
$div.click(); $div.click();
same( a, [1,2], "Check that a click worked with a second toggle." ); deepEqual( a, [1,2], "Check that a click worked with a second toggle." );
same( b, [1], "Check that a click worked with a second toggle." ); deepEqual( b, [1], "Check that a click worked with a second toggle." );
$div.click(); $div.click();
same( a, [1,2,1], "Check that a click worked with a second toggle, second click." ); deepEqual( a, [1,2,1], "Check that a click worked with a second toggle, second click." );
same( b, [1,2], "Check that a click worked with a second toggle, second click." ); deepEqual( b, [1,2], "Check that a click worked with a second toggle, second click." );
// manually clean up detached elements // manually clean up detached elements
$div.remove(); $div.remove();
...@@ -1286,68 +1286,68 @@ test(".live()/.die()", function() { ...@@ -1286,68 +1286,68 @@ test(".live()/.die()", function() {
// Nothing should trigger on the body // Nothing should trigger on the body
jQuery("body").trigger("click"); jQuery("body").trigger("click");
equals( submit, 0, "Click on body" ); equal( submit, 0, "Click on body" );
equals( div, 0, "Click on body" ); equal( div, 0, "Click on body" );
equals( livea, 0, "Click on body" ); equal( livea, 0, "Click on body" );
equals( 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");
equals( submit, 0, "Click on div" ); equal( submit, 0, "Click on div" );
equals( div, 1, "Click on div" ); equal( div, 1, "Click on div" );
equals( livea, 1, "Click on div" ); equal( livea, 1, "Click on div" );
equals( 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");
equals( submit, 0, "Click on inner div" ); equal( submit, 0, "Click on inner div" );
equals( div, 2, "Click on inner div" ); equal( div, 2, "Click on inner div" );
equals( livea, 1, "Click on inner div" ); equal( livea, 1, "Click on inner div" );
equals( 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");
equals( submit, 1, "Submit on div" ); equal( submit, 1, "Submit on div" );
equals( div, 0, "Submit on div" ); equal( div, 0, "Submit on div" );
equals( livea, 0, "Submit on div" ); equal( livea, 0, "Submit on div" );
equals( 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");
equals( submit, 0, "die Click on inner div" ); equal( submit, 0, "die Click on inner div" );
equals( div, 2, "die Click on inner div" ); equal( div, 2, "die Click on inner div" );
equals( livea, 1, "die Click on inner div" ); equal( livea, 1, "die Click on inner div" );
equals( 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");
equals( submit, 0, "die Click on inner div" ); equal( submit, 0, "die Click on inner div" );
equals( div, 2, "die Click on inner div" ); equal( div, 2, "die Click on inner div" );
equals( livea, 1, "die Click on inner div" ); equal( livea, 1, "die Click on inner div" );
equals( 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");
equals( submit, 0, "die Click on inner div" ); equal( submit, 0, "die Click on inner div" );
equals( div, 1, "die Click on inner div" ); equal( div, 1, "die Click on inner div" );
equals( livea, 1, "die Click on inner div" ); equal( livea, 1, "die Click on inner div" );
equals( 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");
equals( submit, 0, "stopPropagation Click on inner div" ); equal( submit, 0, "stopPropagation Click on inner div" );
equals( div, 1, "stopPropagation Click on inner div" ); equal( div, 1, "stopPropagation Click on inner div" );
equals( livea, 0, "stopPropagation Click on inner div" ); equal( livea, 0, "stopPropagation Click on inner div" );
equals( 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;
...@@ -1355,7 +1355,7 @@ test(".live()/.die()", function() { ...@@ -1355,7 +1355,7 @@ test(".live()/.die()", function() {
event.button = 1; event.button = 1;
jQuery("div#nothiddendiv").trigger(event); jQuery("div#nothiddendiv").trigger(event);
equals( livea, 0, "live secondary click" ); equal( livea, 0, "live secondary click" );
jQuery("div#nothiddendivchild").die("click"); jQuery("div#nothiddendivchild").die("click");
jQuery("div#nothiddendiv").die("click"); jQuery("div#nothiddendiv").die("click");
...@@ -1369,30 +1369,30 @@ test(".live()/.die()", function() { ...@@ -1369,30 +1369,30 @@ test(".live()/.die()", function() {
jQuery("#foo").trigger("click"); jQuery("#foo").trigger("click");
jQuery("#qunit-fixture").trigger("click"); jQuery("#qunit-fixture").trigger("click");
jQuery("body").trigger("click"); jQuery("body").trigger("click");
equals( clicked, 2, "live with a context" ); equal( clicked, 2, "live with a context" );
// Test unbinding with a different context // Test unbinding with a different context
jQuery("#foo", container).die("click"); jQuery("#foo", container).die("click");
jQuery("#foo").trigger("click"); jQuery("#foo").trigger("click");
equals( clicked, 2, "die with a context"); equal( clicked, 2, "die with a context");
// Test binding with event data // Test binding with event data
jQuery("#foo").live("click", true, function(e){ equals( e.data, true, "live with event data" ); }); jQuery("#foo").live("click", true, function(e){ equal( e.data, true, "live with event data" ); });
jQuery("#foo").trigger("click").die("click"); jQuery("#foo").trigger("click").die("click");
// Test binding with trigger data // Test binding with trigger data
jQuery("#foo").live("click", function(e, data){ equals( data, true, "live with trigger data" ); }); jQuery("#foo").live("click", function(e, data){ equal( data, true, "live with trigger data" ); });
jQuery("#foo").trigger("click", true).die("click"); jQuery("#foo").trigger("click", true).die("click");
// Test binding with different this object // Test binding with different this object
jQuery("#foo").live("click", jQuery.proxy(function(e){ equals( this.foo, "bar", "live with event scope" ); }, { foo: "bar" })); jQuery("#foo").live("click", jQuery.proxy(function(e){ equal( this.foo, "bar", "live with event scope" ); }, { foo: "bar" }));
jQuery("#foo").trigger("click").die("click"); jQuery("#foo").trigger("click").die("click");
// Test binding with different this object, event data, and trigger data // Test binding with different this object, event data, and trigger data
jQuery("#foo").live("click", true, jQuery.proxy(function(e, data){ jQuery("#foo").live("click", true, jQuery.proxy(function(e, data){
equals( 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" );
equals( 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" );
equals( 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");
...@@ -1400,14 +1400,14 @@ test(".live()/.die()", function() { ...@@ -1400,14 +1400,14 @@ test(".live()/.die()", function() {
jQuery("#anchor2").live("click", function(){ return false; }); jQuery("#anchor2").live("click", function(){ return false; });
var hash = window.location.hash; var hash = window.location.hash;
jQuery("#anchor2").trigger("click"); jQuery("#anchor2").trigger("click");
equals( window.location.hash, hash, "return false worked" ); equal( window.location.hash, hash, "return false worked" );
jQuery("#anchor2").die("click"); jQuery("#anchor2").die("click");
// 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; var hash = window.location.hash;
jQuery("#anchor2").trigger("click"); jQuery("#anchor2").trigger("click");
equals( window.location.hash, hash, "e.preventDefault() worked" ); equal( window.location.hash, hash, "e.preventDefault() worked" );
jQuery("#anchor2").die("click"); jQuery("#anchor2").die("click");
// Test binding the same handler to multiple points // Test binding the same handler to multiple points
...@@ -1418,22 +1418,22 @@ test(".live()/.die()", function() { ...@@ -1418,22 +1418,22 @@ test(".live()/.die()", function() {
jQuery("#anchor2").live("click", callback); jQuery("#anchor2").live("click", callback);
jQuery("#nothiddendiv").trigger("click"); jQuery("#nothiddendiv").trigger("click");
equals( called, 1, "Verify that only one click occurred." ); equal( called, 1, "Verify that only one click occurred." );
called = 0; called = 0;
jQuery("#anchor2").trigger("click"); jQuery("#anchor2").trigger("click");
equals( called, 1, "Verify that only one click occurred." ); equal( called, 1, "Verify that only one click occurred." );
// Make sure that only one callback is removed // Make sure that only one callback is removed
jQuery("#anchor2").die("click", callback); jQuery("#anchor2").die("click", callback);
called = 0; called = 0;
jQuery("#nothiddendiv").trigger("click"); jQuery("#nothiddendiv").trigger("click");
equals( called, 1, "Verify that only one click occurred." ); equal( called, 1, "Verify that only one click occurred." );
called = 0; called = 0;
jQuery("#anchor2").trigger("click"); jQuery("#anchor2").trigger("click");
equals( called, 0, "Verify that no click occurred." ); equal( called, 0, "Verify that no click occurred." );
// Make sure that it still works if the selector is the same, // Make sure that it still works if the selector is the same,
// but the event type is different // but the event type is different
...@@ -1444,11 +1444,11 @@ test(".live()/.die()", function() { ...@@ -1444,11 +1444,11 @@ test(".live()/.die()", function() {
called = 0; called = 0;
jQuery("#nothiddendiv").trigger("click"); jQuery("#nothiddendiv").trigger("click");
equals( called, 0, "Verify that no click occurred." ); equal( called, 0, "Verify that no click occurred." );
called = 0; called = 0;
jQuery("#nothiddendiv").trigger("foo"); jQuery("#nothiddendiv").trigger("foo");
equals( called, 1, "Verify that one foo occurred." ); equal( called, 1, "Verify that one foo occurred." );
// Cleanup // Cleanup
jQuery("#nothiddendiv").die("foo", callback); jQuery("#nothiddendiv").die("foo", callback);
...@@ -1461,8 +1461,8 @@ test(".live()/.die()", function() { ...@@ -1461,8 +1461,8 @@ test(".live()/.die()", function() {
jQuery("#nothiddendivchild").live("click", function(e){ if(e.target) {livec++;} }); jQuery("#nothiddendivchild").live("click", function(e){ if(e.target) {livec++;} });
jQuery("#nothiddendiv span").click(); jQuery("#nothiddendiv span").click();
equals( jQuery("#nothiddendiv span").length, 0, "Verify that first handler occurred and modified the DOM." ); equal( jQuery("#nothiddendiv span").length, 0, "Verify that first handler occurred and modified the DOM." );
equals( livec, 1, "Verify that second handler occurred even with nuked target." ); equal( livec, 1, "Verify that second handler occurred even with nuked target." );
// Cleanup // Cleanup
jQuery("#nothiddendivchild").die("click"); jQuery("#nothiddendivchild").die("click");
...@@ -1476,8 +1476,8 @@ test(".live()/.die()", function() { ...@@ -1476,8 +1476,8 @@ test(".live()/.die()", function() {
jQuery("span#liveSpan1").live("click", function(){ livee++; }); jQuery("span#liveSpan1").live("click", function(){ livee++; });
jQuery("span#liveSpan1 a").click(); jQuery("span#liveSpan1 a").click();
equals( lived, 1, "Verify that only one first handler occurred." ); equal( lived, 1, "Verify that only one first handler occurred." );
equals( livee, 0, "Verify that second handler doesn't." ); equal( livee, 0, "Verify that second handler doesn't." );
// and one pair in inverse // and one pair in inverse
jQuery("span#liveSpan2").live("click", function(){ livee++; }); jQuery("span#liveSpan2").live("click", function(){ livee++; });
...@@ -1486,8 +1486,8 @@ test(".live()/.die()", function() { ...@@ -1486,8 +1486,8 @@ test(".live()/.die()", function() {
lived = 0; lived = 0;
livee = 0; livee = 0;
jQuery("span#liveSpan2 a").click(); jQuery("span#liveSpan2 a").click();
equals( lived, 1, "Verify that only one first handler occurred." ); equal( lived, 1, "Verify that only one first handler occurred." );
equals( 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")
...@@ -1497,10 +1497,10 @@ test(".live()/.die()", function() { ...@@ -1497,10 +1497,10 @@ test(".live()/.die()", function() {
// Test this, target and currentTarget are correct // Test this, target and currentTarget are correct
jQuery("span#liveSpan1").live("click", function(e){ jQuery("span#liveSpan1").live("click", function(e){
equals( this.id, "liveSpan1", "Check the this within a live handler" ); equal( this.id, "liveSpan1", "Check the this within a live handler" );
equals( e.currentTarget.id, "liveSpan1", "Check the event.currentTarget within a live handler" ); equal( e.currentTarget.id, "liveSpan1", "Check the event.currentTarget within a live handler" );
equals( e.delegateTarget, document, "Check the event.delegateTarget within a live handler" ); equal( e.delegateTarget, document, "Check the event.delegateTarget within a live handler" );
equals( e.target.nodeName.toUpperCase(), "A", "Check the event.target within a live handler" ); equal( e.target.nodeName.toUpperCase(), "A", "Check the event.target within a live handler" );
}); });
jQuery("span#liveSpan1 a").click(); jQuery("span#liveSpan1 a").click();
...@@ -1516,31 +1516,31 @@ test(".live()/.die()", function() { ...@@ -1516,31 +1516,31 @@ test(".live()/.die()", function() {
jQuery("#nothiddendiv div").live("click", clickB); jQuery("#nothiddendiv div").live("click", clickB);
jQuery("#nothiddendiv div").live("mouseover", function(){ livee++; }); jQuery("#nothiddendiv div").live("mouseover", function(){ livee++; });
equals( livee, 0, "No clicks, deep selector." ); equal( livee, 0, "No clicks, deep selector." );
livee = 0; livee = 0;
jQuery("#nothiddendivchild").trigger("click"); jQuery("#nothiddendivchild").trigger("click");
equals( livee, 2, "Click, deep selector." ); equal( livee, 2, "Click, deep selector." );
livee = 0; livee = 0;
jQuery("#nothiddendivchild").trigger("mouseover"); jQuery("#nothiddendivchild").trigger("mouseover");
equals( livee, 1, "Mouseover, deep selector." ); equal( livee, 1, "Mouseover, deep selector." );
jQuery("#nothiddendiv div").die("mouseover"); jQuery("#nothiddendiv div").die("mouseover");
livee = 0; livee = 0;
jQuery("#nothiddendivchild").trigger("click"); jQuery("#nothiddendivchild").trigger("click");
equals( livee, 2, "Click, deep selector." ); equal( livee, 2, "Click, deep selector." );
livee = 0; livee = 0;
jQuery("#nothiddendivchild").trigger("mouseover"); jQuery("#nothiddendivchild").trigger("mouseover");
equals( livee, 0, "Mouseover, deep selector." ); equal( livee, 0, "Mouseover, deep selector." );
jQuery("#nothiddendiv div").die("click", clickB); jQuery("#nothiddendiv div").die("click", clickB);
livee = 0; livee = 0;
jQuery("#nothiddendivchild").trigger("click"); jQuery("#nothiddendivchild").trigger("click");
equals( livee, 1, "Click, deep selector." ); equal( livee, 1, "Click, deep selector." );
jQuery("#nothiddendiv div").die("click"); jQuery("#nothiddendiv div").die("click");
...@@ -1567,7 +1567,7 @@ test("die all bound events", function(){ ...@@ -1567,7 +1567,7 @@ test("die all bound events", function(){
div.trigger("click"); div.trigger("click");
div.trigger("submit"); div.trigger("submit");
equals( count, 0, "Make sure no events were triggered." ); equal( count, 0, "Make sure no events were triggered." );
}); });
test("live with multiple events", function(){ test("live with multiple events", function(){
...@@ -1581,7 +1581,7 @@ test("live with multiple events", function(){ ...@@ -1581,7 +1581,7 @@ test("live with multiple events", function(){
div.trigger("click"); div.trigger("click");
div.trigger("submit"); div.trigger("submit");
equals( count, 2, "Make sure both the click and submit were triggered." ); equal( count, 2, "Make sure both the click and submit were triggered." );
// manually clean up events from elements outside the fixture // manually clean up events from elements outside the fixture
div.die(); div.die();
...@@ -1593,24 +1593,24 @@ test("live with namespaces", function(){ ...@@ -1593,24 +1593,24 @@ test("live with namespaces", function(){
var count1 = 0, count2 = 0; var count1 = 0, count2 = 0;
jQuery("#liveSpan1").live("foo.bar", function(e){ jQuery("#liveSpan1").live("foo.bar", function(e){
equals( e.namespace, "bar", "namespace is bar" ); equal( e.namespace, "bar", "namespace is bar" );
count1++; count1++;
}); });
jQuery("#liveSpan1").live("foo.zed", function(e){ jQuery("#liveSpan1").live("foo.zed", function(e){
equals( e.namespace, "zed", "namespace is zed" ); equal( e.namespace, "zed", "namespace is zed" );
count2++; count2++;
}); });
jQuery("#liveSpan1").trigger("foo.bar"); jQuery("#liveSpan1").trigger("foo.bar");
equals( count1, 1, "Got live foo.bar" ); equal( count1, 1, "Got live foo.bar" );
equals( 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");
equals( count1, 0, "Got live foo.zed" ); equal( count1, 0, "Got live foo.zed" );
equals( 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;
...@@ -1618,14 +1618,14 @@ test("live with namespaces", function(){ ...@@ -1618,14 +1618,14 @@ test("live with namespaces", function(){
jQuery("#liveSpan1").die("foo.zed"); jQuery("#liveSpan1").die("foo.zed");
jQuery("#liveSpan1").trigger("foo.bar"); jQuery("#liveSpan1").trigger("foo.bar");
equals( count1, 1, "Got live foo.bar after dieing foo.zed" ); equal( count1, 1, "Got live foo.bar after dieing foo.zed" );
equals( 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");
equals( count1, 0, "Got live foo.zed" ); equal( count1, 0, "Got live foo.zed" );
equals( count2, 0, "Got live foo.zed" ); equal( count2, 0, "Got live foo.zed" );
//remove the other //remove the other
jQuery("#liveSpan1").die("foo.bar"); jQuery("#liveSpan1").die("foo.bar");
...@@ -1633,12 +1633,12 @@ test("live with namespaces", function(){ ...@@ -1633,12 +1633,12 @@ test("live with namespaces", function(){
count1 = 0, count2 = 0; count1 = 0, count2 = 0;
jQuery("#liveSpan1").trigger("foo.bar"); jQuery("#liveSpan1").trigger("foo.bar");
equals( count1, 0, "Did not respond to foo.bar after dieing it" ); equal( count1, 0, "Did not respond to foo.bar after dieing it" );
equals( count2, 0, "Did not respond to foo.bar after dieing it" ); equal( count2, 0, "Did not respond to foo.bar after dieing it" );
jQuery("#liveSpan1").trigger("foo.zed"); jQuery("#liveSpan1").trigger("foo.zed");
equals( count1, 0, "Did not trigger foo.zed again" ); equal( count1, 0, "Did not trigger foo.zed again" );
equals( count2, 0, "Did not trigger foo.zed again" ); equal( count2, 0, "Did not trigger foo.zed again" );
}); });
test("live with change", function(){ test("live with change", function(){
...@@ -1663,17 +1663,17 @@ test("live with change", function(){ ...@@ -1663,17 +1663,17 @@ test("live with change", function(){
selectChange = 0; selectChange = 0;
select[0].selectedIndex = select[0].selectedIndex ? 0 : 1; select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
select.trigger("change"); select.trigger("change");
equals( selectChange, 1, "Change on click." ); equal( selectChange, 1, "Change on click." );
// test keys on select // test keys on select
selectChange = 0; selectChange = 0;
select[0].selectedIndex = select[0].selectedIndex ? 0 : 1; select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
select.trigger("change"); select.trigger("change");
equals( selectChange, 1, "Change on keyup." ); equal( selectChange, 1, "Change on keyup." );
// test click on checkbox // test click on checkbox
checkbox.trigger("change"); checkbox.trigger("change");
equals( checkboxChange, 1, "Change on checkbox." ); equal( checkboxChange, 1, "Change on checkbox." );
// test blur/focus on text // test blur/focus on text
var text = jQuery("#name"), textChange = 0, oldTextVal = text.val(); var text = jQuery("#name"), textChange = 0, oldTextVal = text.val();
...@@ -1683,7 +1683,7 @@ test("live with change", function(){ ...@@ -1683,7 +1683,7 @@ test("live with change", function(){
text.val(oldTextVal+"foo"); text.val(oldTextVal+"foo");
text.trigger("change"); text.trigger("change");
equals( textChange, 1, "Change on text input." ); equal( textChange, 1, "Change on text input." );
text.val(oldTextVal); text.val(oldTextVal);
text.die("change"); text.die("change");
...@@ -1696,7 +1696,7 @@ test("live with change", function(){ ...@@ -1696,7 +1696,7 @@ test("live with change", function(){
password.val(oldPasswordVal + "foo"); password.val(oldPasswordVal + "foo");
password.trigger("change"); password.trigger("change");
equals( passwordChange, 1, "Change on password input." ); equal( passwordChange, 1, "Change on password input." );
password.val(oldPasswordVal); password.val(oldPasswordVal);
password.die("change"); password.die("change");
...@@ -1708,17 +1708,17 @@ test("live with change", function(){ ...@@ -1708,17 +1708,17 @@ test("live with change", function(){
select.die("change"); select.die("change");
select[0].selectedIndex = select[0].selectedIndex ? 0 : 1; select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
select.trigger("change"); select.trigger("change");
equals( selectChange, 0, "Die on click works." ); equal( selectChange, 0, "Die on click works." );
selectChange = 0; selectChange = 0;
select[0].selectedIndex = select[0].selectedIndex ? 0 : 1; select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
select.trigger("change"); select.trigger("change");
equals( selectChange, 0, "Die on keyup works." ); equal( selectChange, 0, "Die on keyup works." );
// die specific checkbox // die specific checkbox
checkbox.die("change", checkboxFunction); checkbox.die("change", checkboxFunction);
checkbox.trigger("change"); checkbox.trigger("change");
equals( checkboxChange, 1, "Die on checkbox." ); equal( checkboxChange, 1, "Die on checkbox." );
}); });
test("live with submit", function() { test("live with submit", function() {
...@@ -1737,20 +1737,20 @@ test("live with submit", function() { ...@@ -1737,20 +1737,20 @@ test("live with submit", function() {
}); });
jQuery("#testForm input[name=sub1]").submit(); jQuery("#testForm input[name=sub1]").submit();
equals( count1, 1, "Verify form submit." ); equal( count1, 1, "Verify form submit." );
equals( count2, 1, "Verify body submit." ); equal( count2, 1, "Verify body submit." );
jQuery("#testForm input[name=sub1]").live("click", function(ev) { jQuery("#testForm input[name=sub1]").live("click", function(ev) {
ok( true, "cancelling submit still calls click handler" ); ok( true, "cancelling submit still calls click handler" );
}); });
jQuery("#testForm input[name=sub1]")[0].click(); jQuery("#testForm input[name=sub1]")[0].click();
equals( count1, 2, "Verify form submit." ); equal( count1, 2, "Verify form submit." );
equals( count2, 2, "Verify body submit." ); equal( count2, 2, "Verify body submit." );
jQuery("#testForm button[name=sub4]")[0].click(); jQuery("#testForm button[name=sub4]")[0].click();
equals( count1, 3, "Verify form submit." ); equal( count1, 3, "Verify form submit." );
equals( count2, 3, "Verify body submit." ); equal( count2, 3, "Verify body submit." );
jQuery("#testForm").die("submit"); jQuery("#testForm").die("submit");
jQuery("#testForm input[name=sub1]").die("click"); jQuery("#testForm input[name=sub1]").die("click");
...@@ -1818,68 +1818,68 @@ test(".delegate()/.undelegate()", function() { ...@@ -1818,68 +1818,68 @@ test(".delegate()/.undelegate()", function() {
// Nothing should trigger on the body // Nothing should trigger on the body
jQuery("body").trigger("click"); jQuery("body").trigger("click");
equals( submit, 0, "Click on body" ); equal( submit, 0, "Click on body" );
equals( div, 0, "Click on body" ); equal( div, 0, "Click on body" );
equals( livea, 0, "Click on body" ); equal( livea, 0, "Click on body" );
equals( 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");
equals( submit, 0, "Click on div" ); equal( submit, 0, "Click on div" );
equals( div, 1, "Click on div" ); equal( div, 1, "Click on div" );
equals( livea, 1, "Click on div" ); equal( livea, 1, "Click on div" );
equals( 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");
equals( submit, 0, "Click on inner div" ); equal( submit, 0, "Click on inner div" );
equals( div, 2, "Click on inner div" ); equal( div, 2, "Click on inner div" );
equals( livea, 1, "Click on inner div" ); equal( livea, 1, "Click on inner div" );
equals( 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");
equals( submit, 1, "Submit on div" ); equal( submit, 1, "Submit on div" );
equals( div, 0, "Submit on div" ); equal( div, 0, "Submit on div" );
equals( livea, 0, "Submit on div" ); equal( livea, 0, "Submit on div" );
equals( 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");
equals( submit, 0, "undelegate Click on inner div" ); equal( submit, 0, "undelegate Click on inner div" );
equals( div, 2, "undelegate Click on inner div" ); equal( div, 2, "undelegate Click on inner div" );
equals( livea, 1, "undelegate Click on inner div" ); equal( livea, 1, "undelegate Click on inner div" );
equals( 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");
equals( submit, 0, "undelegate Click on inner div" ); equal( submit, 0, "undelegate Click on inner div" );
equals( div, 2, "undelegate Click on inner div" ); equal( div, 2, "undelegate Click on inner div" );
equals( livea, 1, "undelegate Click on inner div" ); equal( livea, 1, "undelegate Click on inner div" );
equals( 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");
equals( submit, 0, "undelegate Click on inner div" ); equal( submit, 0, "undelegate Click on inner div" );
equals( div, 1, "undelegate Click on inner div" ); equal( div, 1, "undelegate Click on inner div" );
equals( livea, 1, "undelegate Click on inner div" ); equal( livea, 1, "undelegate Click on inner div" );
equals( 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");
equals( submit, 0, "stopPropagation Click on inner div" ); equal( submit, 0, "stopPropagation Click on inner div" );
equals( div, 1, "stopPropagation Click on inner div" ); equal( div, 1, "stopPropagation Click on inner div" );
equals( livea, 0, "stopPropagation Click on inner div" ); equal( livea, 0, "stopPropagation Click on inner div" );
equals( 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;
...@@ -1887,7 +1887,7 @@ test(".delegate()/.undelegate()", function() { ...@@ -1887,7 +1887,7 @@ test(".delegate()/.undelegate()", function() {
event.button = 1; event.button = 1;
jQuery("div#nothiddendiv").trigger(event); jQuery("div#nothiddendiv").trigger(event);
equals( livea, 0, "delegate secondary click" ); equal( livea, 0, "delegate secondary click" );
jQuery("#body").undelegate("div#nothiddendivchild", "click"); jQuery("#body").undelegate("div#nothiddendivchild", "click");
jQuery("#body").undelegate("div#nothiddendiv", "click"); jQuery("#body").undelegate("div#nothiddendiv", "click");
...@@ -1901,33 +1901,33 @@ test(".delegate()/.undelegate()", function() { ...@@ -1901,33 +1901,33 @@ test(".delegate()/.undelegate()", function() {
jQuery("#foo").trigger("click"); jQuery("#foo").trigger("click");
jQuery("#qunit-fixture").trigger("click"); jQuery("#qunit-fixture").trigger("click");
jQuery("body").trigger("click"); jQuery("body").trigger("click");
equals( clicked, 2, "delegate with a context" ); equal( clicked, 2, "delegate with a context" );
// Test unbinding with a different context // Test unbinding with a different context
jQuery("#qunit-fixture").undelegate("#foo", "click"); jQuery("#qunit-fixture").undelegate("#foo", "click");
jQuery("#foo").trigger("click"); jQuery("#foo").trigger("click");
equals( clicked, 2, "undelegate with a context"); equal( clicked, 2, "undelegate with a context");
// Test binding with event data // Test binding with event data
jQuery("#body").delegate("#foo", "click", true, function(e){ equals( e.data, true, "delegate with event data" ); }); jQuery("#body").delegate("#foo", "click", true, function(e){ equal( e.data, true, "delegate with event data" ); });
jQuery("#foo").trigger("click"); jQuery("#foo").trigger("click");
jQuery("#body").undelegate("#foo", "click"); jQuery("#body").undelegate("#foo", "click");
// Test binding with trigger data // Test binding with trigger data
jQuery("#body").delegate("#foo", "click", function(e, data){ equals( data, true, "delegate with trigger data" ); }); jQuery("#body").delegate("#foo", "click", function(e, data){ equal( data, true, "delegate with trigger data" ); });
jQuery("#foo").trigger("click", true); jQuery("#foo").trigger("click", true);
jQuery("#body").undelegate("#foo", "click"); jQuery("#body").undelegate("#foo", "click");
// Test binding with different this object // Test binding with different this object
jQuery("#body").delegate("#foo", "click", jQuery.proxy(function(e){ equals( this.foo, "bar", "delegate with event scope" ); }, { foo: "bar" })); jQuery("#body").delegate("#foo", "click", jQuery.proxy(function(e){ equal( this.foo, "bar", "delegate with event scope" ); }, { foo: "bar" }));
jQuery("#foo").trigger("click"); jQuery("#foo").trigger("click");
jQuery("#body").undelegate("#foo", "click"); jQuery("#body").undelegate("#foo", "click");
// Test binding with different this object, event data, and trigger data // Test binding with different this object, event data, and trigger data
jQuery("#body").delegate("#foo", "click", true, jQuery.proxy(function(e, data){ jQuery("#body").delegate("#foo", "click", true, jQuery.proxy(function(e, data){
equals( 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" );
equals( 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" );
equals( 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");
...@@ -1936,14 +1936,14 @@ test(".delegate()/.undelegate()", function() { ...@@ -1936,14 +1936,14 @@ test(".delegate()/.undelegate()", function() {
jQuery("#body").delegate("#anchor2", "click", function(){ return false; }); jQuery("#body").delegate("#anchor2", "click", function(){ return false; });
var hash = window.location.hash; var hash = window.location.hash;
jQuery("#anchor2").trigger("click"); jQuery("#anchor2").trigger("click");
equals( window.location.hash, hash, "return false worked" ); equal( window.location.hash, hash, "return false worked" );
jQuery("#body").undelegate("#anchor2", "click"); jQuery("#body").undelegate("#anchor2", "click");
// 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; var hash = window.location.hash;
jQuery("#anchor2").trigger("click"); jQuery("#anchor2").trigger("click");
equals( 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");
// Test binding the same handler to multiple points // Test binding the same handler to multiple points
...@@ -1954,22 +1954,22 @@ test(".delegate()/.undelegate()", function() { ...@@ -1954,22 +1954,22 @@ test(".delegate()/.undelegate()", function() {
jQuery("#body").delegate("#anchor2", "click", callback); jQuery("#body").delegate("#anchor2", "click", callback);
jQuery("#nothiddendiv").trigger("click"); jQuery("#nothiddendiv").trigger("click");
equals( called, 1, "Verify that only one click occurred." ); equal( called, 1, "Verify that only one click occurred." );
called = 0; called = 0;
jQuery("#anchor2").trigger("click"); jQuery("#anchor2").trigger("click");
equals( called, 1, "Verify that only one click occurred." ); equal( called, 1, "Verify that only one click occurred." );
// Make sure that only one callback is removed // Make sure that only one callback is removed
jQuery("#body").undelegate("#anchor2", "click", callback); jQuery("#body").undelegate("#anchor2", "click", callback);
called = 0; called = 0;
jQuery("#nothiddendiv").trigger("click"); jQuery("#nothiddendiv").trigger("click");
equals( called, 1, "Verify that only one click occurred." ); equal( called, 1, "Verify that only one click occurred." );
called = 0; called = 0;
jQuery("#anchor2").trigger("click"); jQuery("#anchor2").trigger("click");
equals( called, 0, "Verify that no click occurred." ); equal( called, 0, "Verify that no click occurred." );
// Make sure that it still works if the selector is the same, // Make sure that it still works if the selector is the same,
// but the event type is different // but the event type is different
...@@ -1980,11 +1980,11 @@ test(".delegate()/.undelegate()", function() { ...@@ -1980,11 +1980,11 @@ test(".delegate()/.undelegate()", function() {
called = 0; called = 0;
jQuery("#nothiddendiv").trigger("click"); jQuery("#nothiddendiv").trigger("click");
equals( called, 0, "Verify that no click occurred." ); equal( called, 0, "Verify that no click occurred." );
called = 0; called = 0;
jQuery("#nothiddendiv").trigger("foo"); jQuery("#nothiddendiv").trigger("foo");
equals( called, 1, "Verify that one foo occurred." ); equal( called, 1, "Verify that one foo occurred." );
// Cleanup // Cleanup
jQuery("#body").undelegate("#nothiddendiv", "foo", callback); jQuery("#body").undelegate("#nothiddendiv", "foo", callback);
...@@ -1997,8 +1997,8 @@ test(".delegate()/.undelegate()", function() { ...@@ -1997,8 +1997,8 @@ test(".delegate()/.undelegate()", function() {
jQuery("#body").delegate("#nothiddendivchild", "click", function(e){ if(e.target) {livec++;} }); jQuery("#body").delegate("#nothiddendivchild", "click", function(e){ if(e.target) {livec++;} });
jQuery("#nothiddendiv span").click(); jQuery("#nothiddendiv span").click();
equals( jQuery("#nothiddendiv span").length, 0, "Verify that first handler occurred and modified the DOM." ); equal( jQuery("#nothiddendiv span").length, 0, "Verify that first handler occurred and modified the DOM." );
equals( livec, 1, "Verify that second handler occurred even with nuked target." ); equal( livec, 1, "Verify that second handler occurred even with nuked target." );
// Cleanup // Cleanup
jQuery("#body").undelegate("#nothiddendivchild", "click"); jQuery("#body").undelegate("#nothiddendivchild", "click");
...@@ -2012,8 +2012,8 @@ test(".delegate()/.undelegate()", function() { ...@@ -2012,8 +2012,8 @@ test(".delegate()/.undelegate()", function() {
jQuery("#body").delegate("span#liveSpan1", "click", function(){ livee++; }); jQuery("#body").delegate("span#liveSpan1", "click", function(){ livee++; });
jQuery("span#liveSpan1 a").click(); jQuery("span#liveSpan1 a").click();
equals( lived, 1, "Verify that only one first handler occurred." ); equal( lived, 1, "Verify that only one first handler occurred." );
equals( livee, 0, "Verify that second handler doesn't." ); equal( livee, 0, "Verify that second handler doesn't." );
// and one pair in inverse // and one pair in inverse
jQuery("#body").delegate("span#liveSpan2", "click", function(){ livee++; }); jQuery("#body").delegate("span#liveSpan2", "click", function(){ livee++; });
...@@ -2022,18 +2022,18 @@ test(".delegate()/.undelegate()", function() { ...@@ -2022,18 +2022,18 @@ test(".delegate()/.undelegate()", function() {
lived = 0; lived = 0;
livee = 0; livee = 0;
jQuery("span#liveSpan2 a").click(); jQuery("span#liveSpan2 a").click();
equals( lived, 1, "Verify that only one first handler occurred." ); equal( lived, 1, "Verify that only one first handler occurred." );
equals( livee, 0, "Verify that second handler doesn't." ); equal( livee, 0, "Verify that second handler doesn't." );
// Cleanup // Cleanup
jQuery("#body").undelegate("click"); jQuery("#body").undelegate("click");
// Test this, target and currentTarget are correct // Test this, target and currentTarget are correct
jQuery("#body").delegate("span#liveSpan1", "click", function(e){ jQuery("#body").delegate("span#liveSpan1", "click", function(e){
equals( this.id, "liveSpan1", "Check the this within a delegate handler" ); equal( this.id, "liveSpan1", "Check the this within a delegate handler" );
equals( e.currentTarget.id, "liveSpan1", "Check the event.currentTarget within a delegate handler" ); equal( e.currentTarget.id, "liveSpan1", "Check the event.currentTarget within a delegate handler" );
equals( e.delegateTarget, document.body, "Check the event.delegateTarget within a delegate handler" ); equal( e.delegateTarget, document.body, "Check the event.delegateTarget within a delegate handler" );
equals( e.target.nodeName.toUpperCase(), "A", "Check the event.target within a delegate handler" ); equal( e.target.nodeName.toUpperCase(), "A", "Check the event.target within a delegate handler" );
}); });
jQuery("span#liveSpan1 a").click(); jQuery("span#liveSpan1 a").click();
...@@ -2049,31 +2049,31 @@ test(".delegate()/.undelegate()", function() { ...@@ -2049,31 +2049,31 @@ test(".delegate()/.undelegate()", function() {
jQuery("#body").delegate("#nothiddendiv div", "click", clickB); jQuery("#body").delegate("#nothiddendiv div", "click", clickB);
jQuery("#body").delegate("#nothiddendiv div", "mouseover", function(){ livee++; }); jQuery("#body").delegate("#nothiddendiv div", "mouseover", function(){ livee++; });
equals( livee, 0, "No clicks, deep selector." ); equal( livee, 0, "No clicks, deep selector." );
livee = 0; livee = 0;
jQuery("#nothiddendivchild").trigger("click"); jQuery("#nothiddendivchild").trigger("click");
equals( livee, 2, "Click, deep selector." ); equal( livee, 2, "Click, deep selector." );
livee = 0; livee = 0;
jQuery("#nothiddendivchild").trigger("mouseover"); jQuery("#nothiddendivchild").trigger("mouseover");
equals( livee, 1, "Mouseover, deep selector." ); equal( livee, 1, "Mouseover, deep selector." );
jQuery("#body").undelegate("#nothiddendiv div", "mouseover"); jQuery("#body").undelegate("#nothiddendiv div", "mouseover");
livee = 0; livee = 0;
jQuery("#nothiddendivchild").trigger("click"); jQuery("#nothiddendivchild").trigger("click");
equals( livee, 2, "Click, deep selector." ); equal( livee, 2, "Click, deep selector." );
livee = 0; livee = 0;
jQuery("#nothiddendivchild").trigger("mouseover"); jQuery("#nothiddendivchild").trigger("mouseover");
equals( livee, 0, "Mouseover, deep selector." ); equal( livee, 0, "Mouseover, deep selector." );
jQuery("#body").undelegate("#nothiddendiv div", "click", clickB); jQuery("#body").undelegate("#nothiddendiv div", "click", clickB);
livee = 0; livee = 0;
jQuery("#nothiddendivchild").trigger("click"); jQuery("#nothiddendivchild").trigger("click");
equals( livee, 1, "Click, deep selector." ); equal( livee, 1, "Click, deep selector." );
jQuery("#body").undelegate("#nothiddendiv div", "click"); jQuery("#body").undelegate("#nothiddendiv div", "click");
}); });
...@@ -2085,7 +2085,7 @@ test("jQuery.off using dispatched jQuery.Event", function() { ...@@ -2085,7 +2085,7 @@ test("jQuery.off using dispatched jQuery.Event", function() {
count = 0; count = 0;
markup markup
.on( "click.name", "a", function( event ) { .on( "click.name", "a", function( event ) {
equals( ++count, 1, "event called once before removal" ); equal( ++count, 1, "event called once before removal" );
jQuery().off( event ); jQuery().off( event );
}) })
.find( "a" ).click().click().end() .find( "a" ).click().click().end()
...@@ -2120,7 +2120,7 @@ test("undelegate all bound events", function(){ ...@@ -2120,7 +2120,7 @@ test("undelegate all bound events", function(){
jQuery("div#nothiddendivchild").trigger("click"); jQuery("div#nothiddendivchild").trigger("click");
jQuery("div#nothiddendivchild").trigger("submit"); jQuery("div#nothiddendivchild").trigger("submit");
equals( count, 0, "Make sure no events were triggered." ); equal( count, 0, "Make sure no events were triggered." );
}); });
test("delegate with multiple events", function(){ test("delegate with multiple events", function(){
...@@ -2134,7 +2134,7 @@ test("delegate with multiple events", function(){ ...@@ -2134,7 +2134,7 @@ test("delegate with multiple events", function(){
jQuery("div#nothiddendivchild").trigger("click"); jQuery("div#nothiddendivchild").trigger("click");
jQuery("div#nothiddendivchild").trigger("submit"); jQuery("div#nothiddendivchild").trigger("submit");
equals( count, 2, "Make sure both the click and submit were triggered." ); equal( count, 2, "Make sure both the click and submit were triggered." );
jQuery("#body").undelegate(); jQuery("#body").undelegate();
}); });
...@@ -2161,17 +2161,17 @@ test("delegate with change", function(){ ...@@ -2161,17 +2161,17 @@ test("delegate with change", function(){
selectChange = 0; selectChange = 0;
select[0].selectedIndex = select[0].selectedIndex ? 0 : 1; select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
select.trigger("change"); select.trigger("change");
equals( selectChange, 1, "Change on click." ); equal( selectChange, 1, "Change on click." );
// test keys on select // test keys on select
selectChange = 0; selectChange = 0;
select[0].selectedIndex = select[0].selectedIndex ? 0 : 1; select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
select.trigger("change"); select.trigger("change");
equals( selectChange, 1, "Change on keyup." ); equal( selectChange, 1, "Change on keyup." );
// test click on checkbox // test click on checkbox
checkbox.trigger("change"); checkbox.trigger("change");
equals( checkboxChange, 1, "Change on checkbox." ); equal( checkboxChange, 1, "Change on checkbox." );
// test blur/focus on text // test blur/focus on text
var text = jQuery("#name"), textChange = 0, oldTextVal = text.val(); var text = jQuery("#name"), textChange = 0, oldTextVal = text.val();
...@@ -2181,7 +2181,7 @@ test("delegate with change", function(){ ...@@ -2181,7 +2181,7 @@ test("delegate with change", function(){
text.val(oldTextVal+"foo"); text.val(oldTextVal+"foo");
text.trigger("change"); text.trigger("change");
equals( textChange, 1, "Change on text input." ); equal( textChange, 1, "Change on text input." );
text.val(oldTextVal); text.val(oldTextVal);
jQuery("#body").die("change"); jQuery("#body").die("change");
...@@ -2194,7 +2194,7 @@ test("delegate with change", function(){ ...@@ -2194,7 +2194,7 @@ test("delegate with change", function(){
password.val(oldPasswordVal + "foo"); password.val(oldPasswordVal + "foo");
password.trigger("change"); password.trigger("change");
equals( passwordChange, 1, "Change on password input." ); equal( passwordChange, 1, "Change on password input." );
password.val(oldPasswordVal); password.val(oldPasswordVal);
jQuery("#body").undelegate("#name", "change"); jQuery("#body").undelegate("#name", "change");
...@@ -2206,17 +2206,17 @@ test("delegate with change", function(){ ...@@ -2206,17 +2206,17 @@ test("delegate with change", function(){
jQuery("#body").undelegate("select[name='S1']", "change"); jQuery("#body").undelegate("select[name='S1']", "change");
select[0].selectedIndex = select[0].selectedIndex ? 0 : 1; select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
select.trigger("change"); select.trigger("change");
equals( selectChange, 0, "Die on click works." ); equal( selectChange, 0, "Die on click works." );
selectChange = 0; selectChange = 0;
select[0].selectedIndex = select[0].selectedIndex ? 0 : 1; select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
select.trigger("change"); select.trigger("change");
equals( selectChange, 0, "Die on keyup works." ); equal( selectChange, 0, "Die on keyup works." );
// die specific checkbox // die specific checkbox
jQuery("#body").undelegate("#check2", "change", checkboxFunction); jQuery("#body").undelegate("#check2", "change", checkboxFunction);
checkbox.trigger("change"); checkbox.trigger("change");
equals( checkboxChange, 1, "Die on checkbox." ); equal( checkboxChange, 1, "Die on checkbox." );
}); });
test("delegate with submit", function() { test("delegate with submit", function() {
...@@ -2233,8 +2233,8 @@ test("delegate with submit", function() { ...@@ -2233,8 +2233,8 @@ test("delegate with submit", function() {
}); });
jQuery("#testForm input[name=sub1]").submit(); jQuery("#testForm input[name=sub1]").submit();
equals( count1, 1, "Verify form submit." ); equal( count1, 1, "Verify form submit." );
equals( count2, 1, "Verify body submit." ); equal( count2, 1, "Verify body submit." );
jQuery("#body").undelegate(); jQuery("#body").undelegate();
jQuery(document).undelegate(); jQuery(document).undelegate();
...@@ -2252,13 +2252,13 @@ test("undelegate() with only namespaces", function() { ...@@ -2252,13 +2252,13 @@ test("undelegate() with only namespaces", function() {
jQuery("a", $delegate).eq(0).trigger("click.ns"); jQuery("a", $delegate).eq(0).trigger("click.ns");
equals( count, 1, "delegated click.ns"); equal( count, 1, "delegated click.ns");
$delegate.undelegate(".ns"); $delegate.undelegate(".ns");
jQuery("a", $delegate).eq(1).trigger("click.ns"); jQuery("a", $delegate).eq(1).trigger("click.ns");
equals( count, 1, "no more .ns after undelegate"); equal( count, 1, "no more .ns after undelegate");
}); });
test("Non DOM element events", function() { test("Non DOM element events", function() {
...@@ -2292,11 +2292,11 @@ test("focusin bubbles", function() { ...@@ -2292,11 +2292,11 @@ test("focusin bubbles", function() {
order = 0; order = 0;
jQuery( "body" ).bind( "focusin.focusinBubblesTest", function(){ jQuery( "body" ).bind( "focusin.focusinBubblesTest", function(){
equals( 1, order++, "focusin on the body second" ); equal( 1, order++, "focusin on the body second" );
}); });
input.bind( "focusin.focusinBubblesTest", function(){ input.bind( "focusin.focusinBubblesTest", function(){
equals( 0, order++, "focusin on the element first" ); equal( 0, order++, "focusin on the element first" );
}); });
// DOM focus method // DOM focus method
...@@ -2355,7 +2355,7 @@ test(".on and .off", function() { ...@@ -2355,7 +2355,7 @@ test(".on and .off", function() {
.click() .click()
.trigger( "click", 17 ) .trigger( "click", 17 )
.off( "click" ); .off( "click" );
equals( counter, 54, "direct event bindings with data" ); equal( counter, 54, "direct event bindings with data" );
// Delegated events only // Delegated events only
counter = 0; counter = 0;
...@@ -2371,7 +2371,7 @@ test(".on and .off", function() { ...@@ -2371,7 +2371,7 @@ test(".on and .off", function() {
.trigger( "click", 17 ) .trigger( "click", 17 )
.end() .end()
.off( "click", "em" ); .off( "click", "em" );
equals( counter, 54, "delegated event bindings with data" ); equal( counter, 54, "delegated event bindings with data" );
// Mixed event bindings and types // Mixed event bindings and types
...@@ -2385,7 +2385,7 @@ test(".on and .off", function() { ...@@ -2385,7 +2385,7 @@ test(".on and .off", function() {
.on( "cluck", mixfn ) .on( "cluck", mixfn )
.trigger( "what!" ) .trigger( "what!" )
.each( function() { .each( function() {
equals( counter, 0, "nothing triggered yet" ); equal( counter, 0, "nothing triggered yet" );
}) })
.find( "em" ) .find( "em" )
.one( "cluck", 3, mixfn ) .one( "cluck", 3, mixfn )
...@@ -2394,12 +2394,12 @@ test(".on and .off", function() { ...@@ -2394,12 +2394,12 @@ test(".on and .off", function() {
.trigger( "cluck", 9 ) // 2+9 + 0+9 = 20 .trigger( "cluck", 9 ) // 2+9 + 0+9 = 20
.end() .end()
.each( function() { .each( function() {
equals( counter, 49, "after triggering em element" ); equal( counter, 49, "after triggering em element" );
}) })
.off( "cluck", function(){} ) // shouldn't remove anything .off( "cluck", function(){} ) // shouldn't remove anything
.trigger( "cluck", 2 ) // 0+2 = 2 .trigger( "cluck", 2 ) // 0+2 = 2
.each( function() { .each( function() {
equals( counter, 51, "after triggering #onandoff cluck" ); equal( counter, 51, "after triggering #onandoff cluck" );
}) })
.find( "b" ) .find( "b" )
.on( "click", 95, mixfn ) .on( "click", 95, mixfn )
...@@ -2409,7 +2409,7 @@ test(".on and .off", function() { ...@@ -2409,7 +2409,7 @@ test(".on and .off", function() {
.off( "click clack cluck" ) .off( "click clack cluck" )
.end() .end()
.each( function() { .each( function() {
equals( counter, 51, "after triggering b" ); equal( counter, 51, "after triggering b" );
}) })
.trigger( "cluck", 3 ) // 0+3 = 3 .trigger( "cluck", 3 ) // 0+3 = 3
.off( "clack", "em", mixfn ) .off( "clack", "em", mixfn )
...@@ -2417,13 +2417,13 @@ test(".on and .off", function() { ...@@ -2417,13 +2417,13 @@ test(".on and .off", function() {
.trigger( "clack" ) // 0 .trigger( "clack" ) // 0
.end() .end()
.each( function() { .each( function() {
equals( counter, 54, "final triggers" ); equal( counter, 54, "final triggers" );
}) })
.off( "click cluck" ); .off( "click cluck" );
// We should have removed all the event handlers ... kinda hacky way to check this // We should have removed all the event handlers ... kinda hacky way to check this
var data = jQuery.data[ jQuery( "#onandoff" )[0].expando ] || {}; var data = jQuery.data[ jQuery( "#onandoff" )[0].expando ] || {};
equals( data.events, undefined, "no events left" ); equal( data.events, undefined, "no events left" );
jQuery("#onandoff").remove(); jQuery("#onandoff").remove();
}); });
...@@ -2444,7 +2444,7 @@ test("delegated events quickIs", function() { ...@@ -2444,7 +2444,7 @@ test("delegated events quickIs", function() {
check = function(el, expect){ check = function(el, expect){
str = ""; str = "";
markup.find( el ).trigger( "blink" ); markup.find( el ).trigger( "blink" );
equals( str, expect, "On " + el ); equal( str, expect, "On " + el );
}, },
func = function(e){ func = function(e){
var tag = this.nodeName.toLowerCase(); var tag = this.nodeName.toLowerCase();
...@@ -2495,7 +2495,7 @@ test("fixHooks extensions", function() { ...@@ -2495,7 +2495,7 @@ test("fixHooks extensions", function() {
// Trigger a native click and ensure the property is set // Trigger a native click and ensure the property is set
$fixture.bind( "click", function( event ) { $fixture.bind( "click", function( event ) {
equals( event.blurrinessLevel, 42, "event.blurrinessLevel was set" ); equal( event.blurrinessLevel, 42, "event.blurrinessLevel was set" );
}); });
fireNative( $fixture[0], 'click' ); fireNative( $fixture[0], 'click' );
...@@ -2515,8 +2515,8 @@ test("fixHooks extensions", function() { ...@@ -2515,8 +2515,8 @@ test("fixHooks extensions", function() {
test("jQuery.isReady", function() { test("jQuery.isReady", function() {
expect(2); expect(2);
equals(notYetReady, true, "jQuery.isReady should not be true before DOM ready"); equal(notYetReady, true, "jQuery.isReady should not be true before DOM ready");
equals(jQuery.isReady, true, "jQuery.isReady should be true once DOM is ready"); equal(jQuery.isReady, true, "jQuery.isReady should be true once DOM is ready");
}); });
// Create an event handler. // Create an event handler.
...@@ -2549,11 +2549,11 @@ test("fixHooks extensions", function() { ...@@ -2549,11 +2549,11 @@ test("fixHooks extensions", function() {
ok(noEarlyExecution, "Handlers bound to DOM ready should not execute before DOM ready"); ok(noEarlyExecution, "Handlers bound to DOM ready should not execute before DOM ready");
// Ensure execution order. // Ensure execution order.
same(order, ["a", "b", "d", "e", "c", "f"], "Bound DOM ready handlers should execute in bind-order, but those bound with jQuery(document).bind( 'ready', fn ) will always execute last"); deepEqual(order, ["a", "b", "d", "e", "c", "f"], "Bound DOM ready handlers should execute in bind-order, but those bound with jQuery(document).bind( 'ready', fn ) will always execute last");
// Ensure handler argument is correct. // Ensure handler argument is correct.
equals(args.a, jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery"); equal(args.a, jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery");
equals(args.b, jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery"); equal(args.b, jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery");
ok(args.c instanceof jQuery.Event, "Argument passed to fn in jQuery(document).bind( 'ready', fn ) should be an event object"); ok(args.c instanceof jQuery.Event, "Argument passed to fn in jQuery(document).bind( 'ready', fn ) should be an event object");
order = []; order = [];
...@@ -2561,15 +2561,15 @@ test("fixHooks extensions", function() { ...@@ -2561,15 +2561,15 @@ test("fixHooks extensions", function() {
// Now that the ready event has fired, again bind to the ready event // Now that the ready event has fired, again bind to the ready event
// in every possible way. These event handlers should execute immediately. // in every possible way. These event handlers should execute immediately.
jQuery(makeHandler("g")); jQuery(makeHandler("g"));
equals(order.pop(), "g", "Event handler should execute immediately"); equal(order.pop(), "g", "Event handler should execute immediately");
equals(args.g, jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery"); equal(args.g, jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery");
jQuery(document).ready(makeHandler("h")); jQuery(document).ready(makeHandler("h"));
equals(order.pop(), "h", "Event handler should execute immediately"); equal(order.pop(), "h", "Event handler should execute immediately");
equals(args.h, jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery"); equal(args.h, jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery");
jQuery(document).bind("ready.readytest", makeHandler("never")); jQuery(document).bind("ready.readytest", makeHandler("never"));
equals(order.length, 0, "Event handler should never execute since DOM ready has already passed"); equal(order.length, 0, "Event handler should never execute since DOM ready has already passed");
// Cleanup. // Cleanup.
jQuery(document).unbind("ready.readytest"); jQuery(document).unbind("ready.readytest");
......
...@@ -9,25 +9,25 @@ var functionReturningObj = function(value) { return (function() { return value; ...@@ -9,25 +9,25 @@ var functionReturningObj = function(value) { return (function() { return value;
test("text()", function() { test("text()", function() {
expect(2); expect(2);
var expected = "This link has class=\"blog\": Simon Willison's Weblog"; var expected = "This link has class=\"blog\": Simon Willison's Weblog";
equals( jQuery("#sap").text(), expected, "Check for merged text of more then one element." ); equal( jQuery("#sap").text(), expected, "Check for merged text of more then one element." );
// Check serialization of text values // Check serialization of text values
equals( jQuery(document.createTextNode("foo")).text(), "foo", "Text node was retreived from .text()." ); equal( jQuery(document.createTextNode("foo")).text(), "foo", "Text node was retreived from .text()." );
}); });
var testText = function(valueObj) { var testText = function(valueObj) {
expect(4); expect(4);
var val = valueObj("<div><b>Hello</b> cruel world!</div>"); var val = valueObj("<div><b>Hello</b> cruel world!</div>");
equals( jQuery("#foo").text(val)[0].innerHTML.replace(/>/g, "&gt;"), "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "Check escaped text" ); equal( jQuery("#foo").text(val)[0].innerHTML.replace(/>/g, "&gt;"), "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "Check escaped text" );
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents(); var j = jQuery("#nonnodes").contents();
j.text(valueObj("hi!")); j.text(valueObj("hi!"));
equals( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" ); equal( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" ); equal( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
// Blackberry 4.6 doesn't maintain comments in the DOM // Blackberry 4.6 doesn't maintain comments in the DOM
equals( jQuery("#nonnodes")[0].childNodes.length < 3 ? 8 : j[2].nodeType, 8, "Check node,textnode,comment with text()" ); equal( jQuery("#nonnodes")[0].childNodes.length < 3 ? 8 : j[2].nodeType, 8, "Check node,textnode,comment with text()" );
} }
test("text(String)", function() { test("text(String)", function() {
...@@ -44,11 +44,11 @@ test("text(Function) with incoming value", function() { ...@@ -44,11 +44,11 @@ test("text(Function) with incoming value", function() {
var old = "This link has class=\"blog\": Simon Willison's Weblog"; var old = "This link has class=\"blog\": Simon Willison's Weblog";
jQuery("#sap").text(function(i, val) { jQuery("#sap").text(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." ); equal( val, old, "Make sure the incoming value is correct." );
return "foobar"; return "foobar";
}); });
equals( jQuery("#sap").text(), "foobar", "Check for merged text of more then one element." ); equal( jQuery("#sap").text(), "foobar", "Check for merged text of more then one element." );
QUnit.reset(); QUnit.reset();
}); });
...@@ -57,13 +57,13 @@ var testWrap = function(val) { ...@@ -57,13 +57,13 @@ var testWrap = function(val) {
expect(19); expect(19);
var defaultText = "Try them out:"; var defaultText = "Try them out:";
var result = jQuery("#first").wrap(val( "<div class='red'><span></span></div>" )).text(); var result = jQuery("#first").wrap(val( "<div class='red'><span></span></div>" )).text();
equals( defaultText, result, "Check for wrapping of on-the-fly html" ); equal( defaultText, result, "Check for wrapping of on-the-fly html" );
ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" ); ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
QUnit.reset(); QUnit.reset();
result = jQuery("#first").wrap(val( document.getElementById("empty") )).parent(); result = jQuery("#first").wrap(val( document.getElementById("empty") )).parent();
ok( result.is("ol"), "Check for element wrapping" ); ok( result.is("ol"), "Check for element wrapping" );
equals( result.text(), defaultText, "Check for element wrapping" ); equal( result.text(), defaultText, "Check for element wrapping" );
QUnit.reset(); QUnit.reset();
jQuery("#check1").click(function() { jQuery("#check1").click(function() {
...@@ -78,8 +78,8 @@ var testWrap = function(val) { ...@@ -78,8 +78,8 @@ var testWrap = function(val) {
j.wrap(val( "<i></i>" )); j.wrap(val( "<i></i>" ));
// Blackberry 4.6 doesn't maintain comments in the DOM // Blackberry 4.6 doesn't maintain comments in the DOM
equals( jQuery("#nonnodes > i").length, jQuery("#nonnodes")[0].childNodes.length, "Check node,textnode,comment wraps ok" ); equal( jQuery("#nonnodes > i").length, jQuery("#nonnodes")[0].childNodes.length, "Check node,textnode,comment wraps ok" );
equals( jQuery("#nonnodes > i").text(), j.text(), "Check node,textnode,comment wraps doesn't hurt text" ); equal( jQuery("#nonnodes > i").text(), j.text(), "Check node,textnode,comment wraps doesn't hurt text" );
// Try wrapping a disconnected node // Try wrapping a disconnected node
var cacheLength = 0; var cacheLength = 0;
...@@ -88,28 +88,28 @@ var testWrap = function(val) { ...@@ -88,28 +88,28 @@ var testWrap = function(val) {
} }
j = jQuery("<label/>").wrap(val( "<li/>" )); j = jQuery("<label/>").wrap(val( "<li/>" ));
equals( j[0].nodeName.toUpperCase(), "LABEL", "Element is a label" ); equal( j[0].nodeName.toUpperCase(), "LABEL", "Element is a label" );
equals( j[0].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" ); equal( j[0].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" );
for (i in jQuery.cache) { for (i in jQuery.cache) {
cacheLength--; cacheLength--;
} }
equals(cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)"); equal(cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)");
// Wrap an element containing a text node // Wrap an element containing a text node
j = jQuery("<span/>").wrap("<div>test</div>"); j = jQuery("<span/>").wrap("<div>test</div>");
equals( j[0].previousSibling.nodeType, 3, "Make sure the previous node is a text element" ); equal( j[0].previousSibling.nodeType, 3, "Make sure the previous node is a text element" );
equals( j[0].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element." ); equal( j[0].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element." );
// Try to wrap an element with multiple elements (should fail) // Try to wrap an element with multiple elements (should fail)
j = jQuery("<div><span></span></div>").children().wrap("<p></p><div></div>"); j = jQuery("<div><span></span></div>").children().wrap("<p></p><div></div>");
equals( j[0].parentNode.parentNode.childNodes.length, 1, "There should only be one element wrapping." ); equal( j[0].parentNode.parentNode.childNodes.length, 1, "There should only be one element wrapping." );
equals( j.length, 1, "There should only be one element (no cloning)." ); equal( j.length, 1, "There should only be one element (no cloning)." );
equals( j[0].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph." ); equal( j[0].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph." );
// Wrap an element with a jQuery set // Wrap an element with a jQuery set
j = jQuery("<span/>").wrap(jQuery("<div></div>")); j = jQuery("<span/>").wrap(jQuery("<div></div>"));
equals( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." ); equal( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
// Wrap an element with a jQuery set and event // Wrap an element with a jQuery set and event
result = jQuery("<div></div>").click(function(){ result = jQuery("<div></div>").click(function(){
...@@ -121,7 +121,7 @@ var testWrap = function(val) { ...@@ -121,7 +121,7 @@ var testWrap = function(val) {
}); });
j = jQuery("<span/>").wrap(result); j = jQuery("<span/>").wrap(result);
equals( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." ); equal( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
j.parent().trigger("click"); j.parent().trigger("click");
...@@ -143,19 +143,19 @@ var testWrapAll = function(val) { ...@@ -143,19 +143,19 @@ var testWrapAll = function(val) {
var p = jQuery("#firstp,#first")[0].parentNode; var p = jQuery("#firstp,#first")[0].parentNode;
var result = jQuery("#firstp,#first").wrapAll(val( "<div class='red'><div class='tmp'></div></div>" )); var result = jQuery("#firstp,#first").wrapAll(val( "<div class='red'><div class='tmp'></div></div>" ));
equals( result.parent().length, 1, "Check for wrapping of on-the-fly html" ); equal( result.parent().length, 1, "Check for wrapping of on-the-fly html" );
ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" ); ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
ok( jQuery("#firstp").parent().parent().is(".red"), "Check if wrapper has class 'red'" ); ok( jQuery("#firstp").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
equals( jQuery("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" ); equal( jQuery("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
equals( 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; var prev = jQuery("#firstp")[0].previousSibling;
var p = jQuery("#first")[0].parentNode; var p = jQuery("#first")[0].parentNode;
var result = jQuery("#firstp,#first").wrapAll(val( document.getElementById("empty") )); var result = jQuery("#firstp,#first").wrapAll(val( document.getElementById("empty") ));
equals( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" ); equal( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" );
equals( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" ); equal( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
equals( 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() {
...@@ -166,28 +166,28 @@ var testWrapInner = function(val) { ...@@ -166,28 +166,28 @@ var testWrapInner = function(val) {
expect(11); expect(11);
var num = jQuery("#first").children().length; var num = jQuery("#first").children().length;
var result = jQuery("#first").wrapInner(val("<div class='red'><div id='tmp'></div></div>")); var result = jQuery("#first").wrapInner(val("<div class='red'><div id='tmp'></div></div>"));
equals( 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" );
equals( 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; var 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>")); var result = jQuery("#first").wrapInner(val("<div class='red'><div id='tmp'></div></div>"));
equals( 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" );
equals( 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; var num = jQuery("#first").children().length;
var result = jQuery("#first").wrapInner(val(document.getElementById("empty"))); var result = jQuery("#first").wrapInner(val(document.getElementById("empty")));
equals( 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" );
equals( jQuery("#first").children().children().length, num, "Verify Elements Intact" ); equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
var div = jQuery("<div/>"); var div = jQuery("<div/>");
div.wrapInner(val("<span></span>")); div.wrapInner(val("<span></span>"));
equals(div.children().length, 1, "The contents were wrapped."); equal(div.children().length, 1, "The contents were wrapped.");
equals(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() {
...@@ -206,21 +206,21 @@ test("unwrap()", function() { ...@@ -206,21 +206,21 @@ test("unwrap()", function() {
var abcd = jQuery("#unwrap1 > span, #unwrap2 > span").get(), var abcd = jQuery("#unwrap1 > span, #unwrap2 > span").get(),
abcdef = jQuery("#unwrap span").get(); abcdef = jQuery("#unwrap span").get();
equals( jQuery("#unwrap1 span").add("#unwrap2 span:first").unwrap().length, 3, "make #unwrap1 and #unwrap2 go away" ); equal( jQuery("#unwrap1 span").add("#unwrap2 span:first").unwrap().length, 3, "make #unwrap1 and #unwrap2 go away" );
same( jQuery("#unwrap > span").get(), abcd, "all four spans should still exist" ); deepEqual( jQuery("#unwrap > span").get(), abcd, "all four spans should still exist" );
same( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap3 > span").get(), "make all b in #unwrap3 go away" ); deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap3 > span").get(), "make all b in #unwrap3 go away" );
same( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap > span.unwrap3").get(), "make #unwrap3 go away" ); deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap > span.unwrap3").get(), "make #unwrap3 go away" );
same( jQuery("#unwrap").children().get(), abcdef, "#unwrap only contains 6 child spans" ); deepEqual( jQuery("#unwrap").children().get(), abcdef, "#unwrap only contains 6 child spans" );
same( jQuery("#unwrap > span").unwrap().get(), jQuery("body > span.unwrap").get(), "make the 6 spans become children of body" ); deepEqual( jQuery("#unwrap > span").unwrap().get(), jQuery("body > span.unwrap").get(), "make the 6 spans become children of body" );
same( jQuery("body > span.unwrap").unwrap().get(), jQuery("body > span.unwrap").get(), "can't unwrap children of body" ); deepEqual( jQuery("body > span.unwrap").unwrap().get(), jQuery("body > span.unwrap").get(), "can't unwrap children of body" );
same( jQuery("body > span.unwrap").unwrap().get(), abcdef, "can't unwrap children of body" ); deepEqual( jQuery("body > span.unwrap").unwrap().get(), abcdef, "can't unwrap children of body" );
same( jQuery("body > span.unwrap").get(), abcdef, "body contains 6 .unwrap child spans" ); deepEqual( jQuery("body > span.unwrap").get(), abcdef, "body contains 6 .unwrap child spans" );
jQuery("body > span.unwrap").remove(); jQuery("body > span.unwrap").remove();
}); });
...@@ -229,23 +229,23 @@ var testAppend = function(valueObj) { ...@@ -229,23 +229,23 @@ var testAppend = function(valueObj) {
expect(41); expect(41);
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>"));
equals( result.text(), defaultText + "buga", "Check if text appending works" ); equal( result.text(), defaultText + "buga", "Check if text appending works" );
equals( 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");
QUnit.reset(); QUnit.reset();
var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:"; var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
jQuery("#sap").append(valueObj(document.getElementById("first"))); jQuery("#sap").append(valueObj(document.getElementById("first")));
equals( jQuery("#sap").text(), expected, "Check for appending of element" ); equal( jQuery("#sap").text(), expected, "Check for appending of element" );
QUnit.reset(); QUnit.reset();
expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
jQuery("#sap").append(valueObj([document.getElementById("first"), document.getElementById("yahoo")])); jQuery("#sap").append(valueObj([document.getElementById("first"), document.getElementById("yahoo")]));
equals( jQuery("#sap").text(), expected, "Check for appending of array of elements" ); equal( jQuery("#sap").text(), expected, "Check for appending of array of elements" );
QUnit.reset(); QUnit.reset();
expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:"; expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
jQuery("#sap").append(valueObj(jQuery("#yahoo, #first"))); jQuery("#sap").append(valueObj(jQuery("#yahoo, #first")));
equals( jQuery("#sap").text(), expected, "Check for appending of jQuery object" ); equal( jQuery("#sap").text(), expected, "Check for appending of jQuery object" );
QUnit.reset(); QUnit.reset();
jQuery("#sap").append(valueObj( 5 )); jQuery("#sap").append(valueObj( 5 ));
...@@ -280,7 +280,7 @@ var testAppend = function(valueObj) { ...@@ -280,7 +280,7 @@ var testAppend = function(valueObj) {
QUnit.reset(); QUnit.reset();
jQuery("#sap").append(valueObj( document.getElementById("form") )); jQuery("#sap").append(valueObj( document.getElementById("form") ));
equals( jQuery("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910 equal( jQuery("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910
QUnit.reset(); QUnit.reset();
var pass = true; var pass = true;
...@@ -300,7 +300,7 @@ var testAppend = function(valueObj) { ...@@ -300,7 +300,7 @@ var testAppend = function(valueObj) {
QUnit.reset(); QUnit.reset();
jQuery("#select1").append(valueObj( "<OPTION>Test</OPTION>" )); jQuery("#select1").append(valueObj( "<OPTION>Test</OPTION>" ));
equals( jQuery("#select1 option:last").text(), "Test", "Appending &lt;OPTION&gt; (all caps)" ); equal( jQuery("#select1 option:last").text(), "Test", "Appending &lt;OPTION&gt; (all caps)" );
jQuery("#table").append(valueObj( "<colgroup></colgroup>" )); jQuery("#table").append(valueObj( "<colgroup></colgroup>" ));
ok( jQuery("#table colgroup").length, "Append colgroup" ); ok( jQuery("#table colgroup").length, "Append colgroup" );
...@@ -319,12 +319,12 @@ var testAppend = function(valueObj) { ...@@ -319,12 +319,12 @@ var testAppend = function(valueObj) {
t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] ); t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
equals( "Two nodes", jQuery("<div />").append("Two", " nodes").text(), "Appending two text nodes (#4011)" ); equal( "Two nodes", jQuery("<div />").append("Two", " nodes").text(), "Appending two text nodes (#4011)" );
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents(); var j = jQuery("#nonnodes").contents();
var d = jQuery("<div/>").appendTo("#nonnodes").append(j); var d = jQuery("<div/>").appendTo("#nonnodes").append(j);
equals( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" ); equal( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
ok( d.contents().length >= 2, "Check node,textnode,comment append works" ); ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
d.contents().appendTo("#nonnodes"); d.contents().appendTo("#nonnodes");
d.remove(); d.remove();
...@@ -332,7 +332,7 @@ var testAppend = function(valueObj) { ...@@ -332,7 +332,7 @@ var testAppend = function(valueObj) {
QUnit.reset(); QUnit.reset();
var $input = jQuery("<input />").attr({ "type": "checkbox", "checked": true }).appendTo('#testForm'); var $input = jQuery("<input />").attr({ "type": "checkbox", "checked": true }).appendTo('#testForm');
equals( $input[0].checked, true, "A checked checkbox that is appended stays checked" ); equal( $input[0].checked, true, "A checked checkbox that is appended stays checked" );
QUnit.reset(); QUnit.reset();
var $radios = jQuery("input:radio[name='R1']"), var $radios = jQuery("input:radio[name='R1']"),
...@@ -340,8 +340,8 @@ var testAppend = function(valueObj) { ...@@ -340,8 +340,8 @@ var testAppend = function(valueObj) {
$radio = $radios.eq(1).click(); $radio = $radios.eq(1).click();
$radioNot[0].checked = false; $radioNot[0].checked = false;
$radios.parent().wrap("<div></div>"); $radios.parent().wrap("<div></div>");
equals( $radio[0].checked, true, "Reappending radios uphold which radio is checked" ); equal( $radio[0].checked, true, "Reappending radios uphold which radio is checked" );
equals( $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();
var prev = jQuery("#sap").children().length; var prev = jQuery("#sap").children().length;
...@@ -352,7 +352,7 @@ var testAppend = function(valueObj) { ...@@ -352,7 +352,7 @@ var testAppend = function(valueObj) {
"<span></span>" "<span></span>"
); );
equals( jQuery("#sap").children().length, prev + 3, "Make sure that multiple arguments works." ); equal( jQuery("#sap").children().length, prev + 3, "Make sure that multiple arguments works." );
QUnit.reset(); QUnit.reset();
} }
...@@ -370,16 +370,16 @@ test("append(Function) with incoming value", function() { ...@@ -370,16 +370,16 @@ test("append(Function) with incoming value", function() {
var defaultText = "Try them out:", old = jQuery("#first").html(); var defaultText = "Try them out:", old = jQuery("#first").html();
var result = jQuery("#first").append(function(i, val){ var result = jQuery("#first").append(function(i, val){
equals( val, old, "Make sure the incoming value is correct." ); equal( val, old, "Make sure the incoming value is correct." );
return "<b>buga</b>"; return "<b>buga</b>";
}); });
equals( result.text(), defaultText + "buga", "Check if text appending works" ); equal( result.text(), defaultText + "buga", "Check if text appending works" );
var select = jQuery("#select3"); var select = jQuery("#select3");
old = select.html(); old = select.html();
equals( select.append(function(i, val){ equal( select.append(function(i, val){
equals( val, old, "Make sure the incoming value is correct." ); equal( val, old, "Make sure the incoming value is correct." );
return "<option value='appendTest'>Append Test</option>"; return "<option value='appendTest'>Append Test</option>";
}).find("option:last-child").attr("value"), "appendTest", "Appending html options to select element"); }).find("option:last-child").attr("value"), "appendTest", "Appending html options to select element");
...@@ -388,36 +388,36 @@ test("append(Function) with incoming value", function() { ...@@ -388,36 +388,36 @@ test("append(Function) with incoming value", function() {
old = jQuery("#sap").html(); old = jQuery("#sap").html();
jQuery("#sap").append(function(i, val){ jQuery("#sap").append(function(i, val){
equals( val, old, "Make sure the incoming value is correct." ); equal( val, old, "Make sure the incoming value is correct." );
return document.getElementById("first"); return document.getElementById("first");
}); });
equals( jQuery("#sap").text(), expected, "Check for appending of element" ); equal( jQuery("#sap").text(), expected, "Check for appending of element" );
QUnit.reset(); QUnit.reset();
expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
old = jQuery("#sap").html(); old = jQuery("#sap").html();
jQuery("#sap").append(function(i, val){ jQuery("#sap").append(function(i, val){
equals( val, old, "Make sure the incoming value is correct." ); equal( val, old, "Make sure the incoming value is correct." );
return [document.getElementById("first"), document.getElementById("yahoo")]; return [document.getElementById("first"), document.getElementById("yahoo")];
}); });
equals( jQuery("#sap").text(), expected, "Check for appending of array of elements" ); equal( jQuery("#sap").text(), expected, "Check for appending of array of elements" );
QUnit.reset(); QUnit.reset();
expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:"; expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
old = jQuery("#sap").html(); old = jQuery("#sap").html();
jQuery("#sap").append(function(i, val){ jQuery("#sap").append(function(i, val){
equals( val, old, "Make sure the incoming value is correct." ); equal( val, old, "Make sure the incoming value is correct." );
return jQuery("#yahoo, #first"); return jQuery("#yahoo, #first");
}); });
equals( jQuery("#sap").text(), expected, "Check for appending of jQuery object" ); equal( jQuery("#sap").text(), expected, "Check for appending of jQuery object" );
QUnit.reset(); QUnit.reset();
old = jQuery("#sap").html(); old = jQuery("#sap").html();
jQuery("#sap").append(function(i, val){ jQuery("#sap").append(function(i, val){
equals( val, old, "Make sure the incoming value is correct." ); equal( val, old, "Make sure the incoming value is correct." );
return 5; return 5;
}); });
ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" ); ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
...@@ -545,8 +545,8 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() { ...@@ -545,8 +545,8 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
var defaultText = "Try them out:" var defaultText = "Try them out:"
jQuery("<b>buga</b>").appendTo("#first"); jQuery("<b>buga</b>").appendTo("#first");
equals( jQuery("#first").text(), defaultText + "buga", "Check if text appending works" ); equal( jQuery("#first").text(), defaultText + "buga", "Check if text appending works" );
equals( 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");
QUnit.reset(); QUnit.reset();
var l = jQuery("#first").children().length + 2; var l = jQuery("#first").children().length + 2;
...@@ -554,18 +554,18 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() { ...@@ -554,18 +554,18 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
jQuery("<strong>test</strong>"); jQuery("<strong>test</strong>");
jQuery([ jQuery("<strong>test</strong>")[0], jQuery("<strong>test</strong>")[0] ]) jQuery([ jQuery("<strong>test</strong>")[0], jQuery("<strong>test</strong>")[0] ])
.appendTo("#first"); .appendTo("#first");
equals( jQuery("#first").children().length, l, "Make sure the elements were inserted." ); equal( jQuery("#first").children().length, l, "Make sure the elements were inserted." );
equals( jQuery("#first").children().last()[0].nodeName.toLowerCase(), "strong", "Verify the last element." ); equal( jQuery("#first").children().last()[0].nodeName.toLowerCase(), "strong", "Verify the last element." );
QUnit.reset(); QUnit.reset();
var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:"; var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
jQuery(document.getElementById("first")).appendTo("#sap"); jQuery(document.getElementById("first")).appendTo("#sap");
equals( jQuery("#sap").text(), expected, "Check for appending of element" ); equal( jQuery("#sap").text(), expected, "Check for appending of element" );
QUnit.reset(); QUnit.reset();
expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
jQuery([document.getElementById("first"), document.getElementById("yahoo")]).appendTo("#sap"); jQuery([document.getElementById("first"), document.getElementById("yahoo")]).appendTo("#sap");
equals( jQuery("#sap").text(), expected, "Check for appending of array of elements" ); equal( jQuery("#sap").text(), expected, "Check for appending of array of elements" );
QUnit.reset(); QUnit.reset();
ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." ); ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." );
...@@ -573,7 +573,7 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() { ...@@ -573,7 +573,7 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
QUnit.reset(); QUnit.reset();
expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:"; expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
jQuery("#yahoo, #first").appendTo("#sap"); jQuery("#yahoo, #first").appendTo("#sap");
equals( jQuery("#sap").text(), expected, "Check for appending of jQuery object" ); equal( jQuery("#sap").text(), expected, "Check for appending of jQuery object" );
QUnit.reset(); QUnit.reset();
jQuery("#select1").appendTo("#foo"); jQuery("#select1").appendTo("#foo");
...@@ -591,7 +591,7 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() { ...@@ -591,7 +591,7 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
QUnit.reset(); QUnit.reset();
div = jQuery("<div/>").appendTo("#qunit-fixture, #moretests"); div = jQuery("<div/>").appendTo("#qunit-fixture, #moretests");
equals( div.length, 2, "appendTo returns the inserted elements" ); equal( div.length, 2, "appendTo returns the inserted elements" );
div.addClass("test"); div.addClass("test");
...@@ -603,14 +603,14 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() { ...@@ -603,14 +603,14 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
div = jQuery("<div/>"); div = jQuery("<div/>");
jQuery("<span>a</span><b>b</b>").filter("span").appendTo( div ); jQuery("<span>a</span><b>b</b>").filter("span").appendTo( div );
equals( div.children().length, 1, "Make sure the right number of children were inserted." ); equal( div.children().length, 1, "Make sure the right number of children were inserted." );
div = jQuery("#moretests div"); div = jQuery("#moretests div");
var num = jQuery("#qunit-fixture div").length; var num = jQuery("#qunit-fixture div").length;
div.remove().appendTo("#qunit-fixture"); div.remove().appendTo("#qunit-fixture");
equals( jQuery("#qunit-fixture div").length, num, "Make sure all the removed divs were inserted." ); equal( jQuery("#qunit-fixture div").length, num, "Make sure all the removed divs were inserted." );
QUnit.reset(); QUnit.reset();
...@@ -625,23 +625,23 @@ var testPrepend = function(val) { ...@@ -625,23 +625,23 @@ var testPrepend = function(val) {
expect(5); expect(5);
var defaultText = "Try them out:" var defaultText = "Try them out:"
var result = jQuery("#first").prepend(val( "<b>buga</b>" )); var result = jQuery("#first").prepend(val( "<b>buga</b>" ));
equals( result.text(), "buga" + defaultText, "Check if text prepending works" ); equal( result.text(), "buga" + defaultText, "Check if text prepending works" );
equals( 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");
QUnit.reset(); QUnit.reset();
var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog"; var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
jQuery("#sap").prepend(val( document.getElementById("first") )); jQuery("#sap").prepend(val( document.getElementById("first") ));
equals( jQuery("#sap").text(), expected, "Check for prepending of element" ); equal( jQuery("#sap").text(), expected, "Check for prepending of element" );
QUnit.reset(); QUnit.reset();
expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
jQuery("#sap").prepend(val( [document.getElementById("first"), document.getElementById("yahoo")] )); jQuery("#sap").prepend(val( [document.getElementById("first"), document.getElementById("yahoo")] ));
equals( jQuery("#sap").text(), expected, "Check for prepending of array of elements" ); equal( jQuery("#sap").text(), expected, "Check for prepending of array of elements" );
QUnit.reset(); QUnit.reset();
expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog"; expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
jQuery("#sap").prepend(val( jQuery("#yahoo, #first") )); jQuery("#sap").prepend(val( jQuery("#yahoo, #first") ));
equals( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" ); equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" );
}; };
test("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() { test("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() {
...@@ -657,15 +657,15 @@ test("prepend(Function) with incoming value", function() { ...@@ -657,15 +657,15 @@ test("prepend(Function) with incoming value", function() {
var defaultText = "Try them out:", old = jQuery("#first").html(); var defaultText = "Try them out:", old = jQuery("#first").html();
var result = jQuery("#first").prepend(function(i, val) { var result = jQuery("#first").prepend(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." ); equal( val, old, "Make sure the incoming value is correct." );
return "<b>buga</b>"; return "<b>buga</b>";
}); });
equals( result.text(), "buga" + defaultText, "Check if text prepending works" ); equal( result.text(), "buga" + defaultText, "Check if text prepending works" );
old = jQuery("#select3").html(); old = jQuery("#select3").html();
equals( jQuery("#select3").prepend(function(i, val) { equal( jQuery("#select3").prepend(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." ); equal( val, old, "Make sure the incoming value is correct." );
return "<option value='prependTest'>Prepend Test</option>"; return "<option value='prependTest'>Prepend Test</option>";
}).find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element"); }).find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element");
...@@ -674,56 +674,56 @@ test("prepend(Function) with incoming value", function() { ...@@ -674,56 +674,56 @@ test("prepend(Function) with incoming value", function() {
old = jQuery("#sap").html(); old = jQuery("#sap").html();
jQuery("#sap").prepend(function(i, val) { jQuery("#sap").prepend(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." ); equal( val, old, "Make sure the incoming value is correct." );
return document.getElementById("first"); return document.getElementById("first");
}); });
equals( jQuery("#sap").text(), expected, "Check for prepending of element" ); equal( jQuery("#sap").text(), expected, "Check for prepending of element" );
QUnit.reset(); QUnit.reset();
expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
old = jQuery("#sap").html(); old = jQuery("#sap").html();
jQuery("#sap").prepend(function(i, val) { jQuery("#sap").prepend(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." ); equal( val, old, "Make sure the incoming value is correct." );
return [document.getElementById("first"), document.getElementById("yahoo")]; return [document.getElementById("first"), document.getElementById("yahoo")];
}); });
equals( jQuery("#sap").text(), expected, "Check for prepending of array of elements" ); equal( jQuery("#sap").text(), expected, "Check for prepending of array of elements" );
QUnit.reset(); QUnit.reset();
expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog"; expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
old = jQuery("#sap").html(); old = jQuery("#sap").html();
jQuery("#sap").prepend(function(i, val) { jQuery("#sap").prepend(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." ); equal( val, old, "Make sure the incoming value is correct." );
return jQuery("#yahoo, #first"); return jQuery("#yahoo, #first");
}); });
equals( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" ); equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" );
}); });
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");
equals( jQuery("#first").text(), "buga" + defaultText, "Check if text prepending works" ); equal( jQuery("#first").text(), "buga" + defaultText, "Check if text prepending works" );
equals( 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");
QUnit.reset(); QUnit.reset();
var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog"; var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
jQuery(document.getElementById("first")).prependTo("#sap"); jQuery(document.getElementById("first")).prependTo("#sap");
equals( jQuery("#sap").text(), expected, "Check for prepending of element" ); equal( jQuery("#sap").text(), expected, "Check for prepending of element" );
QUnit.reset(); QUnit.reset();
expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
jQuery([document.getElementById("first"), document.getElementById("yahoo")]).prependTo("#sap"); jQuery([document.getElementById("first"), document.getElementById("yahoo")]).prependTo("#sap");
equals( jQuery("#sap").text(), expected, "Check for prepending of array of elements" ); equal( jQuery("#sap").text(), expected, "Check for prepending of array of elements" );
QUnit.reset(); QUnit.reset();
expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog"; expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
jQuery("#yahoo, #first").prependTo("#sap"); jQuery("#yahoo, #first").prependTo("#sap");
equals( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" ); equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" );
QUnit.reset(); QUnit.reset();
jQuery("<select id='prependSelect1'></select>").prependTo("form:last"); jQuery("<select id='prependSelect1'></select>").prependTo("form:last");
...@@ -736,26 +736,26 @@ var testBefore = function(val) { ...@@ -736,26 +736,26 @@ var testBefore = function(val) {
expect(6); expect(6);
var expected = "This is a normal link: bugaYahoo"; var expected = "This is a normal link: bugaYahoo";
jQuery("#yahoo").before(val( "<b>buga</b>" )); jQuery("#yahoo").before(val( "<b>buga</b>" ));
equals( jQuery("#en").text(), expected, "Insert String before" ); equal( jQuery("#en").text(), expected, "Insert String before" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: Try them out:Yahoo"; expected = "This is a normal link: Try them out:Yahoo";
jQuery("#yahoo").before(val( document.getElementById("first") )); jQuery("#yahoo").before(val( document.getElementById("first") ));
equals( jQuery("#en").text(), expected, "Insert element before" ); equal( jQuery("#en").text(), expected, "Insert element before" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: Try them out:diveintomarkYahoo"; expected = "This is a normal link: Try them out:diveintomarkYahoo";
jQuery("#yahoo").before(val( [document.getElementById("first"), document.getElementById("mark")] )); jQuery("#yahoo").before(val( [document.getElementById("first"), document.getElementById("mark")] ));
equals( jQuery("#en").text(), expected, "Insert array of elements before" ); equal( jQuery("#en").text(), expected, "Insert array of elements before" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: diveintomarkTry them out:Yahoo"; expected = "This is a normal link: diveintomarkTry them out:Yahoo";
jQuery("#yahoo").before(val( jQuery("#mark, #first") )); jQuery("#yahoo").before(val( jQuery("#mark, #first") ));
equals( jQuery("#en").text(), expected, "Insert jQuery before" ); equal( jQuery("#en").text(), expected, "Insert jQuery before" );
var set = jQuery("<div/>").before("<span>test</span>"); var set = jQuery("<div/>").before("<span>test</span>");
equals( 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." );
equals( 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() {
...@@ -770,48 +770,48 @@ test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() { ...@@ -770,48 +770,48 @@ test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() {
expect(4); expect(4);
var expected = "This is a normal link: bugaYahoo"; var expected = "This is a normal link: bugaYahoo";
jQuery("<b>buga</b>").insertBefore("#yahoo"); jQuery("<b>buga</b>").insertBefore("#yahoo");
equals( jQuery("#en").text(), expected, "Insert String before" ); equal( jQuery("#en").text(), expected, "Insert String before" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: Try them out:Yahoo"; expected = "This is a normal link: Try them out:Yahoo";
jQuery(document.getElementById("first")).insertBefore("#yahoo"); jQuery(document.getElementById("first")).insertBefore("#yahoo");
equals( jQuery("#en").text(), expected, "Insert element before" ); equal( jQuery("#en").text(), expected, "Insert element before" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: Try them out:diveintomarkYahoo"; expected = "This is a normal link: Try them out:diveintomarkYahoo";
jQuery([document.getElementById("first"), document.getElementById("mark")]).insertBefore("#yahoo"); jQuery([document.getElementById("first"), document.getElementById("mark")]).insertBefore("#yahoo");
equals( jQuery("#en").text(), expected, "Insert array of elements before" ); equal( jQuery("#en").text(), expected, "Insert array of elements before" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: diveintomarkTry them out:Yahoo"; expected = "This is a normal link: diveintomarkTry them out:Yahoo";
jQuery("#mark, #first").insertBefore("#yahoo"); jQuery("#mark, #first").insertBefore("#yahoo");
equals( jQuery("#en").text(), expected, "Insert jQuery before" ); equal( jQuery("#en").text(), expected, "Insert jQuery before" );
}); });
var testAfter = function(val) { var testAfter = function(val) {
expect(6); expect(6);
var expected = "This is a normal link: Yahoobuga"; var expected = "This is a normal link: Yahoobuga";
jQuery("#yahoo").after(val( "<b>buga</b>" )); jQuery("#yahoo").after(val( "<b>buga</b>" ));
equals( jQuery("#en").text(), expected, "Insert String after" ); equal( jQuery("#en").text(), expected, "Insert String after" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: YahooTry them out:"; expected = "This is a normal link: YahooTry them out:";
jQuery("#yahoo").after(val( document.getElementById("first") )); jQuery("#yahoo").after(val( document.getElementById("first") ));
equals( jQuery("#en").text(), expected, "Insert element after" ); equal( jQuery("#en").text(), expected, "Insert element after" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: YahooTry them out:diveintomark"; expected = "This is a normal link: YahooTry them out:diveintomark";
jQuery("#yahoo").after(val( [document.getElementById("first"), document.getElementById("mark")] )); jQuery("#yahoo").after(val( [document.getElementById("first"), document.getElementById("mark")] ));
equals( jQuery("#en").text(), expected, "Insert array of elements after" ); equal( jQuery("#en").text(), expected, "Insert array of elements after" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: YahoodiveintomarkTry them out:"; expected = "This is a normal link: YahoodiveintomarkTry them out:";
jQuery("#yahoo").after(val( jQuery("#mark, #first") )); jQuery("#yahoo").after(val( jQuery("#mark, #first") ));
equals( jQuery("#en").text(), expected, "Insert jQuery after" ); equal( jQuery("#en").text(), expected, "Insert jQuery after" );
var set = jQuery("<div/>").after("<span>test</span>"); var set = jQuery("<div/>").after("<span>test</span>");
equals( set[1].nodeName.toLowerCase(), "span", "Insert the element after the disconnected node." ); equal( set[1].nodeName.toLowerCase(), "span", "Insert the element after the disconnected node." );
equals( set.length, 2, "Insert the element after the disconnected node." ); equal( set.length, 2, "Insert the element after the disconnected node." );
}; };
test("after(String|Element|Array&lt;Element&gt;|jQuery)", function() { test("after(String|Element|Array&lt;Element&gt;|jQuery)", function() {
...@@ -826,22 +826,22 @@ test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() { ...@@ -826,22 +826,22 @@ test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() {
expect(4); expect(4);
var expected = "This is a normal link: Yahoobuga"; var expected = "This is a normal link: Yahoobuga";
jQuery("<b>buga</b>").insertAfter("#yahoo"); jQuery("<b>buga</b>").insertAfter("#yahoo");
equals( jQuery("#en").text(), expected, "Insert String after" ); equal( jQuery("#en").text(), expected, "Insert String after" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: YahooTry them out:"; expected = "This is a normal link: YahooTry them out:";
jQuery(document.getElementById("first")).insertAfter("#yahoo"); jQuery(document.getElementById("first")).insertAfter("#yahoo");
equals( jQuery("#en").text(), expected, "Insert element after" ); equal( jQuery("#en").text(), expected, "Insert element after" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: YahooTry them out:diveintomark"; expected = "This is a normal link: YahooTry them out:diveintomark";
jQuery([document.getElementById("first"), document.getElementById("mark")]).insertAfter("#yahoo"); jQuery([document.getElementById("first"), document.getElementById("mark")]).insertAfter("#yahoo");
equals( jQuery("#en").text(), expected, "Insert array of elements after" ); equal( jQuery("#en").text(), expected, "Insert array of elements after" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: YahoodiveintomarkTry them out:"; expected = "This is a normal link: YahoodiveintomarkTry them out:";
jQuery("#mark, #first").insertAfter("#yahoo"); jQuery("#mark, #first").insertAfter("#yahoo");
equals( jQuery("#en").text(), expected, "Insert jQuery after" ); equal( jQuery("#en").text(), expected, "Insert jQuery after" );
}); });
var testReplaceWith = function(val) { var testReplaceWith = function(val) {
...@@ -858,7 +858,7 @@ var testReplaceWith = function(val) { ...@@ -858,7 +858,7 @@ var testReplaceWith = function(val) {
QUnit.reset(); QUnit.reset();
jQuery("#qunit-fixture").append("<div id='bar'><div id='baz'</div></div>"); jQuery("#qunit-fixture").append("<div id='bar'><div id='baz'</div></div>");
jQuery("#baz").replaceWith("Baz"); jQuery("#baz").replaceWith("Baz");
equals( jQuery("#bar").text(),"Baz", "Replace element with text" ); equal( jQuery("#bar").text(),"Baz", "Replace element with text" );
ok( !jQuery("#baz")[0], "Verify that original element is gone, after element" ); ok( !jQuery("#baz")[0], "Verify that original element is gone, after element" );
QUnit.reset(); QUnit.reset();
...@@ -903,30 +903,30 @@ var testReplaceWith = function(val) { ...@@ -903,30 +903,30 @@ var testReplaceWith = function(val) {
QUnit.reset(); QUnit.reset();
var set = jQuery("<div/>").replaceWith(val("<span>test</span>")); var set = jQuery("<div/>").replaceWith(val("<span>test</span>"));
equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." ); equal( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." );
equals( set.length, 1, "Replace the disconnected node." ); equal( set.length, 1, "Replace the disconnected node." );
var non_existant = jQuery("#does-not-exist").replaceWith( val("<b>should not throw an error</b>") ); var non_existant = jQuery("#does-not-exist").replaceWith( val("<b>should not throw an error</b>") );
equals( non_existant.length, 0, "Length of non existant element." ); equal( non_existant.length, 0, "Length of non existant element." );
var $div = jQuery("<div class='replacewith'></div>").appendTo("body"); var $div = jQuery("<div class='replacewith'></div>").appendTo("body");
// TODO: Work on jQuery(...) inline script execution // TODO: Work on jQuery(...) inline script execution
//$div.replaceWith("<div class='replacewith'></div><script>" + //$div.replaceWith("<div class='replacewith'></div><script>" +
//"equals(jQuery('.replacewith').length, 1, 'Check number of elements in page.');" + //"equal(jQuery('.replacewith').length, 1, 'Check number of elements in page.');" +
//"</script>"); //"</script>");
equals(jQuery(".replacewith").length, 1, "Check number of elements in page."); equal(jQuery(".replacewith").length, 1, "Check number of elements in page.");
jQuery(".replacewith").remove(); jQuery(".replacewith").remove();
QUnit.reset(); QUnit.reset();
jQuery("#qunit-fixture").append("<div id='replaceWith'></div>"); jQuery("#qunit-fixture").append("<div id='replaceWith'></div>");
equals( 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." );
jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") ); jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") );
equals( 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." );
jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") ); jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") );
equals( 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() {
...@@ -941,7 +941,7 @@ test("replaceWith(Function)", function() { ...@@ -941,7 +941,7 @@ test("replaceWith(Function)", function() {
var y = jQuery("#yahoo")[0]; var y = jQuery("#yahoo")[0];
jQuery(y).replaceWith(function(){ jQuery(y).replaceWith(function(){
equals( this, y, "Make sure the context is coming in correctly." ); equal( this, y, "Make sure the context is coming in correctly." );
}); });
QUnit.reset(); QUnit.reset();
...@@ -950,11 +950,11 @@ test("replaceWith(Function)", function() { ...@@ -950,11 +950,11 @@ test("replaceWith(Function)", function() {
test("replaceWith(string) for more than one element", function(){ test("replaceWith(string) for more than one element", function(){
expect(3); expect(3);
equals(jQuery("#foo p").length, 3, "ensuring that test data has not changed"); equal(jQuery("#foo p").length, 3, "ensuring that test data has not changed");
jQuery("#foo p").replaceWith("<span>bar</span>"); jQuery("#foo p").replaceWith("<span>bar</span>");
equals(jQuery("#foo span").length, 3, "verify that all the three original element have been replaced"); equal(jQuery("#foo span").length, 3, "verify that all the three original element have been replaced");
equals(jQuery("#foo p").length, 0, "verify that all the three original element have been replaced"); equal(jQuery("#foo p").length, 0, "verify that all the three original element have been replaced");
}); });
test("replaceAll(String|Element|Array&lt;Element&gt;|jQuery)", function() { test("replaceAll(String|Element|Array&lt;Element&gt;|jQuery)", function() {
...@@ -990,7 +990,7 @@ test("jQuery.clone() (#8017)", function() { ...@@ -990,7 +990,7 @@ test("jQuery.clone() (#8017)", function() {
var main = jQuery("#qunit-fixture")[0], var main = jQuery("#qunit-fixture")[0],
clone = jQuery.clone( main ); clone = jQuery.clone( main );
equals( main.childNodes.length, clone.childNodes.length, "Simple child length to ensure a large dom tree copies correctly" ); equal( main.childNodes.length, clone.childNodes.length, "Simple child length to ensure a large dom tree copies correctly" );
}); });
test("clone() (#8070)", function () { test("clone() (#8070)", function () {
...@@ -1000,18 +1000,18 @@ test("clone() (#8070)", function () { ...@@ -1000,18 +1000,18 @@ test("clone() (#8070)", function () {
var selects = jQuery(".test8070"); var selects = jQuery(".test8070");
selects.append("<OPTION>1</OPTION><OPTION>2</OPTION>"); selects.append("<OPTION>1</OPTION><OPTION>2</OPTION>");
equals( selects[0].childNodes.length, 2, "First select got two nodes" ); equal( selects[0].childNodes.length, 2, "First select got two nodes" );
equals( selects[1].childNodes.length, 2, "Second select got two nodes" ); equal( selects[1].childNodes.length, 2, "Second select got two nodes" );
selects.remove(); selects.remove();
}); });
test("clone()", function() { test("clone()", function() {
expect(40); expect(40);
equals( "This is a normal link: Yahoo", jQuery("#en").text(), "Assert text for #en" ); equal( "This is a normal link: Yahoo", jQuery("#en").text(), "Assert text for #en" );
var clone = jQuery("#yahoo").clone(); var clone = jQuery("#yahoo").clone();
equals( "Try them out:Yahoo", jQuery("#first").append(clone).text(), "Check for clone" ); equal( "Try them out:Yahoo", jQuery("#first").append(clone).text(), "Check for clone" );
equals( "This is a normal link: Yahoo", jQuery("#en").text(), "Reassert text for #en" ); equal( "This is a normal link: Yahoo", jQuery("#en").text(), "Reassert text for #en" );
var cloneTags = [ var cloneTags = [
"<table/>", "<tr/>", "<td/>", "<div/>", "<table/>", "<tr/>", "<td/>", "<div/>",
...@@ -1021,7 +1021,7 @@ test("clone()", function() { ...@@ -1021,7 +1021,7 @@ test("clone()", function() {
]; ];
for (var i = 0; i < cloneTags.length; i++) { for (var i = 0; i < cloneTags.length; i++) {
var j = jQuery(cloneTags[i]); var j = jQuery(cloneTags[i]);
equals( j[0].tagName, j.clone()[0].tagName, "Clone a " + cloneTags[i]); equal( j[0].tagName, j.clone()[0].tagName, "Clone a " + cloneTags[i]);
} }
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
...@@ -1042,8 +1042,8 @@ test("clone()", function() { ...@@ -1042,8 +1042,8 @@ test("clone()", function() {
// manually clean up detached elements // manually clean up detached elements
clone.remove(); clone.remove();
equals( div.length, 1, "One element cloned" ); equal( div.length, 1, "One element cloned" );
equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); equal( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
div.trigger("click"); div.trigger("click");
// manually clean up detached elements // manually clean up detached elements
...@@ -1055,8 +1055,8 @@ test("clone()", function() { ...@@ -1055,8 +1055,8 @@ test("clone()", function() {
}); });
clone = div.clone(true); clone = div.clone(true);
equals( clone.length, 1, "One element cloned" ); equal( clone.length, 1, "One element cloned" );
equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); equal( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
clone.find("table:last").trigger("click"); clone.find("table:last").trigger("click");
// manually clean up detached elements // manually clean up detached elements
...@@ -1078,9 +1078,9 @@ test("clone()", function() { ...@@ -1078,9 +1078,9 @@ test("clone()", function() {
div = jQuery("<div/>").html('<embed height="355" width="425" src="http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en"></embed>'); div = jQuery("<div/>").html('<embed height="355" width="425" src="http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en"></embed>');
clone = div.clone(true); clone = div.clone(true);
equals( clone.length, 1, "One element cloned" ); equal( clone.length, 1, "One element cloned" );
equals( clone.html(), div.html(), "Element contents cloned" ); equal( clone.html(), div.html(), "Element contents cloned" );
equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); equal( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
// this is technically an invalid object, but because of the special // this is technically an invalid object, but because of the special
// classid instantiation it is the only kind that IE has trouble with, // classid instantiation it is the only kind that IE has trouble with,
...@@ -1088,24 +1088,24 @@ test("clone()", function() { ...@@ -1088,24 +1088,24 @@ test("clone()", function() {
div = jQuery("<div/>").html("<object height='355' width='425' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'> <param name='movie' value='http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en'> <param name='wmode' value='transparent'> </object>"); div = jQuery("<div/>").html("<object height='355' width='425' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'> <param name='movie' value='http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en'> <param name='wmode' value='transparent'> </object>");
clone = div.clone(true); clone = div.clone(true);
equals( clone.length, 1, "One element cloned" ); equal( clone.length, 1, "One element cloned" );
equals( clone.html(), div.html(), "Element contents cloned" ); equal( clone.html(), div.html(), "Element contents cloned" );
equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); equal( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
// and here's a valid one. // and here's a valid one.
div = jQuery("<div/>").html("<object height='355' width='425' type='application/x-shockwave-flash' data='http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en'> <param name='movie' value='http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en'> <param name='wmode' value='transparent'> </object>"); div = jQuery("<div/>").html("<object height='355' width='425' type='application/x-shockwave-flash' data='http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en'> <param name='movie' value='http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en'> <param name='wmode' value='transparent'> </object>");
clone = div.clone(true); clone = div.clone(true);
equals( clone.length, 1, "One element cloned" ); equal( clone.length, 1, "One element cloned" );
equals( clone.html(), div.html(), "Element contents cloned" ); equal( clone.html(), div.html(), "Element contents cloned" );
equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); equal( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
div = jQuery("<div/>").data({ a: true }); div = jQuery("<div/>").data({ a: true });
clone = div.clone(true); clone = div.clone(true);
equals( clone.data("a"), true, "Data cloned." ); equal( clone.data("a"), true, "Data cloned." );
clone.data("a", false); clone.data("a", false);
equals( clone.data("a"), false, "Ensure cloned element data object was correctly modified" ); equal( clone.data("a"), false, "Ensure cloned element data object was correctly modified" );
equals( div.data("a"), true, "Ensure cloned element data object is copied, not referenced" ); equal( div.data("a"), true, "Ensure cloned element data object is copied, not referenced" );
// manually clean up detached elements // manually clean up detached elements
div.remove(); div.remove();
...@@ -1117,7 +1117,7 @@ test("clone()", function() { ...@@ -1117,7 +1117,7 @@ test("clone()", function() {
div.appendChild( document.createTextNode("test") ); div.appendChild( document.createTextNode("test") );
form.appendChild( div ); form.appendChild( div );
equals( jQuery(form).clone().children().length, 1, "Make sure we just get the form back." ); equal( jQuery(form).clone().children().length, 1, "Make sure we just get the form back." );
equal( jQuery("body").clone().children()[0].id, "qunit-header", "Make sure cloning body works" ); equal( jQuery("body").clone().children()[0].id, "qunit-header", "Make sure cloning body works" );
}); });
...@@ -1126,31 +1126,31 @@ test("clone(form element) (Bug #3879, #6655)", function() { ...@@ -1126,31 +1126,31 @@ 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 element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>");
equals( 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" );
element = jQuery("<input type='checkbox' value='foo'>").attr("checked", "checked"); element = jQuery("<input type='checkbox' value='foo'>").attr("checked", "checked");
clone = element.clone(); clone = element.clone();
equals( clone.is(":checked"), element.is(":checked"), "Checked input cloned correctly" ); equal( clone.is(":checked"), element.is(":checked"), "Checked input cloned correctly" );
equals( clone[0].defaultValue, "foo", "Checked input defaultValue cloned correctly" ); equal( clone[0].defaultValue, "foo", "Checked input defaultValue cloned correctly" );
// defaultChecked also gets set now due to setAttribute in attr, is this check still valid? // defaultChecked also gets set now due to setAttribute in attr, is this check still valid?
// equals( clone[0].defaultChecked, !jQuery.support.noCloneChecked, "Checked input defaultChecked cloned correctly" ); // equal( clone[0].defaultChecked, !jQuery.support.noCloneChecked, "Checked input defaultChecked cloned correctly" );
element = jQuery("<input type='text' value='foo'>"); element = jQuery("<input type='text' value='foo'>");
clone = element.clone(); clone = element.clone();
equals( clone[0].defaultValue, "foo", "Text input defaultValue cloned correctly" ); equal( clone[0].defaultValue, "foo", "Text input defaultValue cloned correctly" );
element = jQuery("<textarea>foo</textarea>"); element = jQuery("<textarea>foo</textarea>");
clone = element.clone(); clone = element.clone();
equals( clone[0].defaultValue, "foo", "Textarea defaultValue cloned correctly" ); equal( clone[0].defaultValue, "foo", "Textarea defaultValue cloned correctly" );
}); });
test("clone(multiple selected options) (Bug #8129)", function() { test("clone(multiple selected options) (Bug #8129)", function() {
expect(1); expect(1);
var element = jQuery("<select><option>Foo</option><option selected>Bar</option><option selected>Baz</option></select>"); var element = jQuery("<select><option>Foo</option><option selected>Bar</option><option selected>Baz</option></select>");
equals( element.clone().find("option:selected").length, element.find("option:selected").length, "Multiple selected options cloned correctly" ); equal( element.clone().find("option:selected").length, element.find("option:selected").length, "Multiple selected options cloned correctly" );
}); });
...@@ -1164,8 +1164,8 @@ test("clone() on XML nodes", function() { ...@@ -1164,8 +1164,8 @@ test("clone() on XML nodes", function() {
var cloneTab = jQuery("tab", root).eq(0); var cloneTab = jQuery("tab", root).eq(0);
origTab.text("origval"); origTab.text("origval");
cloneTab.text("cloneval"); cloneTab.text("cloneval");
equals(origTab.text(), "origval", "Check original XML node was correctly set"); equal(origTab.text(), "origval", "Check original XML node was correctly set");
equals(cloneTab.text(), "cloneval", "Check cloned XML node was correctly set"); equal(cloneTab.text(), "cloneval", "Check cloned XML node was correctly set");
start(); start();
}); });
}); });
...@@ -1186,17 +1186,17 @@ var testHtml = function(valueObj) { ...@@ -1186,17 +1186,17 @@ var testHtml = function(valueObj) {
div = jQuery("<div/>").html( valueObj("<div id='parent_1'><div id='child_1'/></div><div id='parent_2'/>") ); div = jQuery("<div/>").html( valueObj("<div id='parent_1'><div id='child_1'/></div><div id='parent_2'/>") );
equals( div.children().length, 2, "Make sure two child nodes exist." ); equal( div.children().length, 2, "Make sure two child nodes exist." );
equals( div.children().children().length, 1, "Make sure that a grandchild exists." ); equal( div.children().children().length, 1, "Make sure that a grandchild exists." );
var space = jQuery("<div/>").html(valueObj("&#160;"))[0].innerHTML; var space = jQuery("<div/>").html(valueObj("&#160;"))[0].innerHTML;
ok( /^\xA0$|^&nbsp;$/.test( space ), "Make sure entities are passed through correctly." ); ok( /^\xA0$|^&nbsp;$/.test( space ), "Make sure entities are passed through correctly." );
equals( jQuery("<div/>").html(valueObj("&amp;"))[0].innerHTML, "&amp;", "Make sure entities are passed through correctly." ); equal( jQuery("<div/>").html(valueObj("&amp;"))[0].innerHTML, "&amp;", "Make sure entities are passed through correctly." );
jQuery("#qunit-fixture").html(valueObj("<style>.foobar{color:green;}</style>")); jQuery("#qunit-fixture").html(valueObj("<style>.foobar{color:green;}</style>"));
equals( jQuery("#qunit-fixture").children().length, 1, "Make sure there is a child element." ); equal( jQuery("#qunit-fixture").children().length, 1, "Make sure there is a child element." );
equals( jQuery("#qunit-fixture").children()[0].nodeName.toUpperCase(), "STYLE", "And that a style element was inserted." ); equal( jQuery("#qunit-fixture").children()[0].nodeName.toUpperCase(), "STYLE", "And that a style element was inserted." );
QUnit.reset(); QUnit.reset();
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
...@@ -1205,25 +1205,25 @@ var testHtml = function(valueObj) { ...@@ -1205,25 +1205,25 @@ var testHtml = function(valueObj) {
// this is needed, or the expando added by jQuery unique will yield a different html // this is needed, or the expando added by jQuery unique will yield a different html
j.find("b").removeData(); j.find("b").removeData();
equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" ); equal( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
jQuery("#qunit-fixture").html(valueObj("<select/>")); jQuery("#qunit-fixture").html(valueObj("<select/>"));
jQuery("#qunit-fixture select").html(valueObj("<option>O1</option><option selected='selected'>O2</option><option>O3</option>")); jQuery("#qunit-fixture select").html(valueObj("<option>O1</option><option selected='selected'>O2</option><option>O3</option>"));
equals( jQuery("#qunit-fixture select").val(), "O2", "Selected option correct" ); equal( jQuery("#qunit-fixture select").val(), "O2", "Selected option correct" );
var $div = jQuery("<div />"); var $div = jQuery("<div />");
equals( $div.html(valueObj( 5 )).html(), "5", "Setting a number as html" ); equal( $div.html(valueObj( 5 )).html(), "5", "Setting a number as html" );
equals( $div.html(valueObj( 0 )).html(), "0", "Setting a zero as html" ); equal( $div.html(valueObj( 0 )).html(), "0", "Setting a zero as html" );
var $div2 = jQuery("<div/>"), insert = "&lt;div&gt;hello1&lt;/div&gt;"; var $div2 = jQuery("<div/>"), insert = "&lt;div&gt;hello1&lt;/div&gt;";
equals( $div2.html(insert).html().replace(/>/g, "&gt;"), insert, "Verify escaped insertion." ); equal( $div2.html(insert).html().replace(/>/g, "&gt;"), insert, "Verify escaped insertion." );
equals( $div2.html("x" + insert).html().replace(/>/g, "&gt;"), "x" + insert, "Verify escaped insertion." ); equal( $div2.html("x" + insert).html().replace(/>/g, "&gt;"), "x" + insert, "Verify escaped insertion." );
equals( $div2.html(" " + insert).html().replace(/>/g, "&gt;"), " " + insert, "Verify escaped insertion." ); equal( $div2.html(" " + insert).html().replace(/>/g, "&gt;"), " " + insert, "Verify escaped insertion." );
var map = jQuery("<map/>").html(valueObj("<area id='map01' shape='rect' coords='50,50,150,150' href='http://www.jquery.com/' alt='jQuery'>")); var map = jQuery("<map/>").html(valueObj("<area id='map01' shape='rect' coords='50,50,150,150' href='http://www.jquery.com/' alt='jQuery'>"));
equals( map[0].childNodes.length, 1, "The area was inserted." ); equal( map[0].childNodes.length, 1, "The area was inserted." );
equals( map[0].firstChild.nodeName.toLowerCase(), "area", "The area was inserted." ); equal( map[0].firstChild.nodeName.toLowerCase(), "area", "The area was inserted." );
QUnit.reset(); QUnit.reset();
...@@ -1231,9 +1231,9 @@ var testHtml = function(valueObj) { ...@@ -1231,9 +1231,9 @@ var testHtml = function(valueObj) {
var child = jQuery("#qunit-fixture").find("script"); var child = jQuery("#qunit-fixture").find("script");
equals( child.length, 2, "Make sure that two non-JavaScript script tags are left." ); equal( child.length, 2, "Make sure that two non-JavaScript script tags are left." );
equals( child[0].type, "something/else", "Verify type of script tag." ); equal( child[0].type, "something/else", "Verify type of script tag." );
equals( child[1].type, "something/else", "Verify type of script tag." ); equal( child[1].type, "something/else", "Verify type of script tag." );
jQuery("#qunit-fixture").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>")); jQuery("#qunit-fixture").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
jQuery("#qunit-fixture").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>")); jQuery("#qunit-fixture").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
...@@ -1243,7 +1243,7 @@ var testHtml = function(valueObj) { ...@@ -1243,7 +1243,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>equals(jQuery.scriptorder++, 0, 'Script is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html (even though appears before)')<\/script><span id='scriptorder'><script>equals(jQuery.scriptorder++, 1, 'Script (nested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script></span><script>equals(jQuery.scriptorder++, 2, 'Script (unnested) is executed in order');equals(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() {
...@@ -1271,7 +1271,7 @@ test("html(Function) with incoming value", function() { ...@@ -1271,7 +1271,7 @@ test("html(Function) with incoming value", function() {
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) {
equals( val, old[i], "Make sure the incoming value is correct." ); equal( val, old[i], "Make sure the incoming value is correct." );
return "<b>test</b>"; return "<b>test</b>";
}); });
...@@ -1289,43 +1289,43 @@ test("html(Function) with incoming value", function() { ...@@ -1289,43 +1289,43 @@ test("html(Function) with incoming value", function() {
old = j.map(function(){ return jQuery(this).html(); }); old = j.map(function(){ return jQuery(this).html(); });
j.html(function(i, val) { j.html(function(i, val) {
equals( val, old[i], "Make sure the incoming value is correct." ); equal( val, old[i], "Make sure the incoming value is correct." );
return "<b>bold</b>"; return "<b>bold</b>";
}); });
// Handle the case where no comment is in the document // Handle the case where no comment is in the document
if ( j.length === 2 ) { if ( j.length === 2 ) {
equals( null, null, "Make sure the incoming value is correct." ); equal( null, null, "Make sure the incoming value is correct." );
} }
j.find("b").removeData(); j.find("b").removeData();
equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" ); equal( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
var $div = jQuery("<div />"); var $div = jQuery("<div />");
equals( $div.html(function(i, val) { equal( $div.html(function(i, val) {
equals( val, "", "Make sure the incoming value is correct." ); equal( val, "", "Make sure the incoming value is correct." );
return 5; return 5;
}).html(), "5", "Setting a number as html" ); }).html(), "5", "Setting a number as html" );
equals( $div.html(function(i, val) { equal( $div.html(function(i, val) {
equals( val, "5", "Make sure the incoming value is correct." ); equal( val, "5", "Make sure the incoming value is correct." );
return 0; return 0;
}).html(), "0", "Setting a zero as html" ); }).html(), "0", "Setting a zero as html" );
var $div2 = jQuery("<div/>"), insert = "&lt;div&gt;hello1&lt;/div&gt;"; var $div2 = jQuery("<div/>"), insert = "&lt;div&gt;hello1&lt;/div&gt;";
equals( $div2.html(function(i, val) { equal( $div2.html(function(i, val) {
equals( val, "", "Make sure the incoming value is correct." ); equal( val, "", "Make sure the incoming value is correct." );
return insert; return insert;
}).html().replace(/>/g, "&gt;"), insert, "Verify escaped insertion." ); }).html().replace(/>/g, "&gt;"), insert, "Verify escaped insertion." );
equals( $div2.html(function(i, val) { equal( $div2.html(function(i, val) {
equals( val.replace(/>/g, "&gt;"), insert, "Make sure the incoming value is correct." ); equal( val.replace(/>/g, "&gt;"), insert, "Make sure the incoming value is correct." );
return "x" + insert; return "x" + insert;
}).html().replace(/>/g, "&gt;"), "x" + insert, "Verify escaped insertion." ); }).html().replace(/>/g, "&gt;"), "x" + insert, "Verify escaped insertion." );
equals( $div2.html(function(i, val) { equal( $div2.html(function(i, val) {
equals( val.replace(/>/g, "&gt;"), "x" + insert, "Make sure the incoming value is correct." ); equal( val.replace(/>/g, "&gt;"), "x" + insert, "Make sure the incoming value is correct." );
return " " + insert; return " " + insert;
}).html().replace(/>/g, "&gt;"), " " + insert, "Verify escaped insertion." ); }).html().replace(/>/g, "&gt;"), " " + insert, "Verify escaped insertion." );
}); });
...@@ -1338,23 +1338,23 @@ var testRemove = function(method) { ...@@ -1338,23 +1338,23 @@ var testRemove = function(method) {
jQuery("#ap").children()[method](); jQuery("#ap").children()[method]();
ok( jQuery("#ap").text().length > 10, "Check text is not removed" ); ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
equals( jQuery("#ap").children().length, 0, "Check remove" ); equal( jQuery("#ap").children().length, 0, "Check remove" );
equals( first.data("foo"), method == "remove" ? null : "bar" ); equal( first.data("foo"), method == "remove" ? null : "bar" );
QUnit.reset(); QUnit.reset();
jQuery("#ap").children()[method]("a"); jQuery("#ap").children()[method]("a");
ok( jQuery("#ap").text().length > 10, "Check text is not removed" ); ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
equals( jQuery("#ap").children().length, 1, "Check filtered remove" ); equal( jQuery("#ap").children().length, 1, "Check filtered remove" );
jQuery("#ap").children()[method]("a, code"); jQuery("#ap").children()[method]("a, code");
equals( jQuery("#ap").children().length, 0, "Check multi-filtered remove" ); equal( jQuery("#ap").children().length, 0, "Check multi-filtered remove" );
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
// Handle the case where no comment is in the document // Handle the case where no comment is in the document
ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment remove works" ); ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment remove works" );
jQuery("#nonnodes").contents()[method](); jQuery("#nonnodes").contents()[method]();
equals( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" ); equal( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
// manually clean up detached elements // manually clean up detached elements
if (method === "detach") { if (method === "detach") {
...@@ -1367,7 +1367,7 @@ var testRemove = function(method) { ...@@ -1367,7 +1367,7 @@ var testRemove = function(method) {
var first = jQuery("#ap").children(":first"); var first = jQuery("#ap").children(":first");
var cleanUp = first.click(function() { count++ })[method]().appendTo("#qunit-fixture").click(); var cleanUp = first.click(function() { count++ })[method]().appendTo("#qunit-fixture").click();
equals( method == "remove" ? 0 : 1, count ); equal( method == "remove" ? 0 : 1, count );
// manually clean up detached elements // manually clean up detached elements
cleanUp.remove(); cleanUp.remove();
...@@ -1383,13 +1383,13 @@ test("detach()", function() { ...@@ -1383,13 +1383,13 @@ test("detach()", function() {
test("empty()", function() { test("empty()", function() {
expect(3); expect(3);
equals( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" ); equal( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" );
equals( jQuery("#ap").children().length, 4, "Check elements are not removed" ); equal( jQuery("#ap").children().length, 4, "Check elements are not removed" );
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents(); var j = jQuery("#nonnodes").contents();
j.empty(); j.empty();
equals( j.html(), "", "Check node,textnode,comment empty works" ); equal( j.html(), "", "Check node,textnode,comment empty works" );
}); });
test("jQuery.cleanData", function() { test("jQuery.cleanData", function() {
...@@ -1482,7 +1482,7 @@ test("jQuery.buildFragment - no plain-text caching (Bug #6779)", function() { ...@@ -1482,7 +1482,7 @@ test("jQuery.buildFragment - no plain-text caching (Bug #6779)", function() {
} }
catch(e) {} catch(e) {}
} }
equals($f.text(), bad.join(""), "Cached strings that match Object properties"); equal($f.text(), bad.join(""), "Cached strings that match Object properties");
$f.remove(); $f.remove();
}); });
......
...@@ -5,8 +5,8 @@ test("disconnected node", function() { ...@@ -5,8 +5,8 @@ test("disconnected node", function() {
var result = jQuery( document.createElement("div") ).offset(); var result = jQuery( document.createElement("div") ).offset();
equals( result.top, 0, "Check top" ); equal( result.top, 0, "Check top" );
equals( result.left, 0, "Check left" ); equal( result.left, 0, "Check left" );
}); });
var supportsScroll = false; var supportsScroll = false;
...@@ -34,8 +34,8 @@ testoffset("absolute", function($, iframe) { ...@@ -34,8 +34,8 @@ testoffset("absolute", function($, iframe) {
{ id: "#absolute-1", top: 1, left: 1 } { id: "#absolute-1", top: 1, left: 1 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equals( jQuery( this.id, doc ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" ); equal( jQuery( this.id, doc ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" );
equals( jQuery( this.id, doc ).offset().left, this.left, "jQuery('" + this.id + "').offset().left" ); equal( jQuery( this.id, doc ).offset().left, this.left, "jQuery('" + this.id + "').offset().left" );
}); });
...@@ -44,8 +44,8 @@ testoffset("absolute", function($, iframe) { ...@@ -44,8 +44,8 @@ testoffset("absolute", function($, iframe) {
{ id: "#absolute-1", top: 0, left: 0 } { id: "#absolute-1", top: 0, left: 0 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equals( jQuery( this.id, doc ).position().top, this.top, "jQuery('" + this.id + "').position().top" ); equal( jQuery( this.id, doc ).position().top, this.top, "jQuery('" + this.id + "').position().top" );
equals( jQuery( this.id, doc ).position().left, this.left, "jQuery('" + this.id + "').position().left" ); equal( jQuery( this.id, doc ).position().left, this.left, "jQuery('" + this.id + "').position().left" );
}); });
forceScroll.remove(); forceScroll.remove();
...@@ -62,8 +62,8 @@ testoffset("absolute", function( jQuery ) { ...@@ -62,8 +62,8 @@ testoffset("absolute", function( jQuery ) {
{ id: "#absolute-2", top: 20, left: 20 } { id: "#absolute-2", top: 20, left: 20 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" ); equal( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" );
equals( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset().left" ); equal( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset().left" );
}); });
...@@ -75,14 +75,14 @@ testoffset("absolute", function( jQuery ) { ...@@ -75,14 +75,14 @@ testoffset("absolute", function( jQuery ) {
{ id: "#absolute-2", top: 19, left: 19 } { id: "#absolute-2", top: 19, left: 19 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equals( jQuery( this.id ).position().top, this.top, "jQuery('" + this.id + "').position().top" ); equal( jQuery( this.id ).position().top, this.top, "jQuery('" + this.id + "').position().top" );
equals( jQuery( this.id ).position().left, this.left, "jQuery('" + this.id + "').position().left" ); equal( jQuery( this.id ).position().left, this.left, "jQuery('" + this.id + "').position().left" );
}); });
// test #5781 // test #5781
var offset = jQuery( "#positionTest" ).offset({ top: 10, left: 10 }).offset(); var offset = jQuery( "#positionTest" ).offset({ top: 10, left: 10 }).offset();
equals( 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." )
equals( 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
...@@ -106,24 +106,24 @@ testoffset("absolute", function( jQuery ) { ...@@ -106,24 +106,24 @@ testoffset("absolute", function( jQuery ) {
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
jQuery( this.id ).offset({ top: this.top, left: this.left }); jQuery( this.id ).offset({ top: this.top, left: this.left });
equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset({ top: " + this.top + " })" ); equal( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset({ top: " + this.top + " })" );
equals( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset({ left: " + this.left + " })" ); equal( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset({ left: " + this.left + " })" );
var top = this.top, left = this.left; var top = this.top, left = this.left;
jQuery( this.id ).offset(function(i, val){ jQuery( this.id ).offset(function(i, val){
equals( val.top, top, "Verify incoming top position." ); equal( val.top, top, "Verify incoming top position." );
equals( val.left, left, "Verify incoming top position." ); equal( val.left, left, "Verify incoming top position." );
return { top: top + 1, left: left + 1 }; return { top: top + 1, left: left + 1 };
}); });
equals( jQuery( this.id ).offset().top, this.top + 1, "jQuery('" + this.id + "').offset({ top: " + (this.top + 1) + " })" ); equal( jQuery( this.id ).offset().top, this.top + 1, "jQuery('" + this.id + "').offset({ top: " + (this.top + 1) + " })" );
equals( jQuery( this.id ).offset().left, this.left + 1, "jQuery('" + this.id + "').offset({ left: " + (this.left + 1) + " })" ); equal( jQuery( this.id ).offset().left, this.left + 1, "jQuery('" + this.id + "').offset({ left: " + (this.left + 1) + " })" );
jQuery( this.id ) jQuery( this.id )
.offset({ left: this.left + 2 }) .offset({ left: this.left + 2 })
.offset({ top: this.top + 2 }); .offset({ top: this.top + 2 });
equals( jQuery( this.id ).offset().top, this.top + 2, "Setting one property at a time." ); equal( jQuery( this.id ).offset().top, this.top + 2, "Setting one property at a time." );
equals( jQuery( this.id ).offset().left, this.left + 2, "Setting one property at a time." ); equal( jQuery( this.id ).offset().left, this.left + 2, "Setting one property at a time." );
jQuery( this.id ).offset({ top: this.top, left: this.left, using: function( props ) { jQuery( this.id ).offset({ top: this.top, left: this.left, using: function( props ) {
jQuery( this ).css({ jQuery( this ).css({
...@@ -131,8 +131,8 @@ testoffset("absolute", function( jQuery ) { ...@@ -131,8 +131,8 @@ testoffset("absolute", function( jQuery ) {
left: props.left + 1 left: props.left + 1
}); });
}}); }});
equals( jQuery( this.id ).offset().top, this.top + 1, "jQuery('" + this.id + "').offset({ top: " + (this.top + 1) + ", using: fn })" ); equal( jQuery( this.id ).offset().top, this.top + 1, "jQuery('" + this.id + "').offset({ top: " + (this.top + 1) + ", using: fn })" );
equals( jQuery( this.id ).offset().left, this.left + 1, "jQuery('" + this.id + "').offset({ left: " + (this.left + 1) + ", using: fn })" ); equal( jQuery( this.id ).offset().left, this.left + 1, "jQuery('" + this.id + "').offset({ left: " + (this.left + 1) + ", using: fn })" );
}); });
}); });
...@@ -149,8 +149,8 @@ testoffset("relative", function( jQuery ) { ...@@ -149,8 +149,8 @@ testoffset("relative", function( jQuery ) {
{ id: "#relative-2", top: ie ? 141 : 142, left: 27 } { id: "#relative-2", top: ie ? 141 : 142, left: 27 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" ); equal( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" );
equals( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset().left" ); equal( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset().left" );
}); });
...@@ -161,8 +161,8 @@ testoffset("relative", function( jQuery ) { ...@@ -161,8 +161,8 @@ testoffset("relative", function( jQuery ) {
{ id: "#relative-2", top: ie ? 140 : 141, left: 26 } { id: "#relative-2", top: ie ? 140 : 141, left: 26 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equals( jQuery( this.id ).position().top, this.top, "jQuery('" + this.id + "').position().top" ); equal( jQuery( this.id ).position().top, this.top, "jQuery('" + this.id + "').position().top" );
equals( jQuery( this.id ).position().left, this.left, "jQuery('" + this.id + "').position().left" ); equal( jQuery( this.id ).position().left, this.left, "jQuery('" + this.id + "').position().left" );
}); });
...@@ -183,8 +183,8 @@ testoffset("relative", function( jQuery ) { ...@@ -183,8 +183,8 @@ testoffset("relative", function( jQuery ) {
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
jQuery( this.id ).offset({ top: this.top, left: this.left }); jQuery( this.id ).offset({ top: this.top, left: this.left });
equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset({ top: " + this.top + " })" ); equal( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset({ top: " + this.top + " })" );
equals( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset({ left: " + this.left + " })" ); equal( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset({ left: " + this.left + " })" );
jQuery( this.id ).offset({ top: this.top, left: this.left, using: function( props ) { jQuery( this.id ).offset({ top: this.top, left: this.left, using: function( props ) {
jQuery( this ).css({ jQuery( this ).css({
...@@ -192,8 +192,8 @@ testoffset("relative", function( jQuery ) { ...@@ -192,8 +192,8 @@ testoffset("relative", function( jQuery ) {
left: props.left + 1 left: props.left + 1
}); });
}}); }});
equals( jQuery( this.id ).offset().top, this.top + 1, "jQuery('" + this.id + "').offset({ top: " + (this.top + 1) + ", using: fn })" ); equal( jQuery( this.id ).offset().top, this.top + 1, "jQuery('" + this.id + "').offset({ top: " + (this.top + 1) + ", using: fn })" );
equals( jQuery( this.id ).offset().left, this.left + 1, "jQuery('" + this.id + "').offset({ left: " + (this.left + 1) + ", using: fn })" ); equal( jQuery( this.id ).offset().left, this.left + 1, "jQuery('" + this.id + "').offset({ left: " + (this.left + 1) + ", using: fn })" );
}); });
}); });
...@@ -211,8 +211,8 @@ testoffset("static", function( jQuery ) { ...@@ -211,8 +211,8 @@ testoffset("static", function( jQuery ) {
{ id: "#static-2", top: ie ? 121 : 122, left: 7 } { id: "#static-2", top: ie ? 121 : 122, left: 7 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" ); equal( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" );
equals( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset().left" ); equal( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset().left" );
}); });
...@@ -224,8 +224,8 @@ testoffset("static", function( jQuery ) { ...@@ -224,8 +224,8 @@ testoffset("static", function( jQuery ) {
{ id: "#static-2", top: ie ? 120 : 121, left: 6 } { id: "#static-2", top: ie ? 120 : 121, left: 6 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equals( jQuery( this.id ).position().top, this.top, "jQuery('" + this.top + "').position().top" ); equal( jQuery( this.id ).position().top, this.top, "jQuery('" + this.top + "').position().top" );
equals( jQuery( this.id ).position().left, this.left, "jQuery('" + this.left +"').position().left" ); equal( jQuery( this.id ).position().left, this.left, "jQuery('" + this.left +"').position().left" );
}); });
...@@ -250,8 +250,8 @@ testoffset("static", function( jQuery ) { ...@@ -250,8 +250,8 @@ testoffset("static", function( jQuery ) {
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
jQuery( this.id ).offset({ top: this.top, left: this.left }); jQuery( this.id ).offset({ top: this.top, left: this.left });
equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset({ top: " + this.top + " })" ); equal( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset({ top: " + this.top + " })" );
equals( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset({ left: " + this.left + " })" ); equal( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset({ left: " + this.left + " })" );
jQuery( this.id ).offset({ top: this.top, left: this.left, using: function( props ) { jQuery( this.id ).offset({ top: this.top, left: this.left, using: function( props ) {
jQuery( this ).css({ jQuery( this ).css({
...@@ -259,8 +259,8 @@ testoffset("static", function( jQuery ) { ...@@ -259,8 +259,8 @@ testoffset("static", function( jQuery ) {
left: props.left + 1 left: props.left + 1
}); });
}}); }});
equals( jQuery( this.id ).offset().top, this.top + 1, "jQuery('" + this.id + "').offset({ top: " + (this.top + 1) + ", using: fn })" ); equal( jQuery( this.id ).offset().top, this.top + 1, "jQuery('" + this.id + "').offset({ top: " + (this.top + 1) + ", using: fn })" );
equals( jQuery( this.id ).offset().left, this.left + 1, "jQuery('" + this.id + "').offset({ left: " + (this.left + 1) + ", using: fn })" ); equal( jQuery( this.id ).offset().left, this.left + 1, "jQuery('" + this.id + "').offset({ left: " + (this.left + 1) + ", using: fn })" );
}); });
}); });
...@@ -278,8 +278,8 @@ testoffset("fixed", function( jQuery ) { ...@@ -278,8 +278,8 @@ testoffset("fixed", function( jQuery ) {
ok( true, "Browser doesn't support scroll position." ); ok( true, "Browser doesn't support scroll position." );
} else if ( jQuery.offset.supportsFixedPosition ) { } else if ( jQuery.offset.supportsFixedPosition ) {
equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" ); equal( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" );
equals( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset().left" ); equal( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset().left" );
} else { } else {
// need to have same number of assertions // need to have same number of assertions
ok( true, "Fixed position is not supported" ); ok( true, "Fixed position is not supported" );
...@@ -299,8 +299,8 @@ testoffset("fixed", function( jQuery ) { ...@@ -299,8 +299,8 @@ testoffset("fixed", function( jQuery ) {
jQuery.each( tests, function() { jQuery.each( tests, function() {
if ( jQuery.offset.supportsFixedPosition ) { if ( jQuery.offset.supportsFixedPosition ) {
jQuery( this.id ).offset({ top: this.top, left: this.left }); jQuery( this.id ).offset({ top: this.top, left: this.left });
equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset({ top: " + this.top + " })" ); equal( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset({ top: " + this.top + " })" );
equals( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset({ left: " + this.left + " })" ); equal( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset({ left: " + this.left + " })" );
jQuery( this.id ).offset({ top: this.top, left: this.left, using: function( props ) { jQuery( this.id ).offset({ top: this.top, left: this.left, using: function( props ) {
jQuery( this ).css({ jQuery( this ).css({
...@@ -308,8 +308,8 @@ testoffset("fixed", function( jQuery ) { ...@@ -308,8 +308,8 @@ testoffset("fixed", function( jQuery ) {
left: props.left + 1 left: props.left + 1
}); });
}}); }});
equals( jQuery( this.id ).offset().top, this.top + 1, "jQuery('" + this.id + "').offset({ top: " + (this.top + 1) + ", using: fn })" ); equal( jQuery( this.id ).offset().top, this.top + 1, "jQuery('" + this.id + "').offset({ top: " + (this.top + 1) + ", using: fn })" );
equals( jQuery( this.id ).offset().left, this.left + 1, "jQuery('" + this.id + "').offset({ left: " + (this.left + 1) + ", using: fn })" ); equal( jQuery( this.id ).offset().left, this.left + 1, "jQuery('" + this.id + "').offset({ left: " + (this.left + 1) + ", using: fn })" );
} else { } else {
// need to have same number of assertions // need to have same number of assertions
ok( true, "Fixed position is not supported" ); ok( true, "Fixed position is not supported" );
...@@ -322,8 +322,8 @@ testoffset("fixed", function( jQuery ) { ...@@ -322,8 +322,8 @@ testoffset("fixed", function( jQuery ) {
// Bug 8316 // Bug 8316
var $noTopLeft = jQuery("#fixed-no-top-left"); var $noTopLeft = jQuery("#fixed-no-top-left");
if ( jQuery.offset.supportsFixedPosition ) { if ( jQuery.offset.supportsFixedPosition ) {
equals( $noTopLeft.offset().top, 1007, "Check offset top for fixed element with no top set" ); equal( $noTopLeft.offset().top, 1007, "Check offset top for fixed element with no top set" );
equals( $noTopLeft.offset().left, 1007, "Check offset left for fixed element with no left set" ); equal( $noTopLeft.offset().left, 1007, "Check offset left for fixed element with no left set" );
} else { } else {
// need to have same number of assertions // need to have same number of assertions
ok( true, "Fixed position is not supported" ); ok( true, "Fixed position is not supported" );
...@@ -334,11 +334,11 @@ testoffset("fixed", function( jQuery ) { ...@@ -334,11 +334,11 @@ testoffset("fixed", function( jQuery ) {
testoffset("table", function( jQuery ) { testoffset("table", function( jQuery ) {
expect(4); expect(4);
equals( jQuery("#table-1").offset().top, 6, "jQuery('#table-1').offset().top" ); equal( jQuery("#table-1").offset().top, 6, "jQuery('#table-1').offset().top" );
equals( jQuery("#table-1").offset().left, 6, "jQuery('#table-1').offset().left" ); equal( jQuery("#table-1").offset().left, 6, "jQuery('#table-1').offset().left" );
equals( jQuery("#th-1").offset().top, 10, "jQuery('#th-1').offset().top" ); equal( jQuery("#th-1").offset().top, 10, "jQuery('#th-1').offset().top" );
equals( jQuery("#th-1").offset().left, 10, "jQuery('#th-1').offset().left" ); equal( jQuery("#th-1").offset().left, 10, "jQuery('#th-1').offset().left" );
}); });
testoffset("scroll", function( jQuery, win ) { testoffset("scroll", function( jQuery, win ) {
...@@ -347,23 +347,23 @@ testoffset("scroll", function( jQuery, win ) { ...@@ -347,23 +347,23 @@ testoffset("scroll", function( jQuery, win ) {
var ie = jQuery.browser.msie && parseInt( jQuery.browser.version, 10 ) < 8; var ie = jQuery.browser.msie && parseInt( jQuery.browser.version, 10 ) < 8;
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( jQuery("#scroll-1").offset().top, ie ? 6 : 7, "jQuery('#scroll-1').offset().top" ); equal( jQuery("#scroll-1").offset().top, ie ? 6 : 7, "jQuery('#scroll-1').offset().top" );
equals( jQuery("#scroll-1").offset().left, 7, "jQuery('#scroll-1').offset().left" ); equal( jQuery("#scroll-1").offset().left, 7, "jQuery('#scroll-1').offset().left" );
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( jQuery("#scroll-1-1").offset().top, ie ? 9 : 11, "jQuery('#scroll-1-1').offset().top" ); equal( jQuery("#scroll-1-1").offset().top, ie ? 9 : 11, "jQuery('#scroll-1-1').offset().top" );
equals( jQuery("#scroll-1-1").offset().left, 11, "jQuery('#scroll-1-1').offset().left" ); equal( jQuery("#scroll-1-1").offset().left, 11, "jQuery('#scroll-1-1').offset().left" );
// scroll offset tests .scrollTop/Left // scroll offset tests .scrollTop/Left
equals( jQuery("#scroll-1").scrollTop(), 5, "jQuery('#scroll-1').scrollTop()" ); equal( jQuery("#scroll-1").scrollTop(), 5, "jQuery('#scroll-1').scrollTop()" );
equals( jQuery("#scroll-1").scrollLeft(), 5, "jQuery('#scroll-1').scrollLeft()" ); equal( jQuery("#scroll-1").scrollLeft(), 5, "jQuery('#scroll-1').scrollLeft()" );
equals( jQuery("#scroll-1-1").scrollTop(), 0, "jQuery('#scroll-1-1').scrollTop()" ); equal( jQuery("#scroll-1-1").scrollTop(), 0, "jQuery('#scroll-1-1').scrollTop()" );
equals( jQuery("#scroll-1-1").scrollLeft(), 0, "jQuery('#scroll-1-1').scrollLeft()" ); equal( jQuery("#scroll-1-1").scrollLeft(), 0, "jQuery('#scroll-1-1').scrollLeft()" );
// equals( jQuery("body").scrollTop(), 0, "jQuery("body").scrollTop()" ); // equal( jQuery("body").scrollTop(), 0, "jQuery("body").scrollTop()" );
// equals( jQuery("body").scrollLeft(), 0, "jQuery("body").scrollTop()" ); // equal( jQuery("body").scrollLeft(), 0, "jQuery("body").scrollTop()" );
win.name = "test"; win.name = "test";
...@@ -374,20 +374,20 @@ testoffset("scroll", function( jQuery, win ) { ...@@ -374,20 +374,20 @@ testoffset("scroll", function( jQuery, win ) {
ok( true, "Browser doesn't support scroll position." ); ok( true, "Browser doesn't support scroll position." );
ok( true, "Browser doesn't support scroll position." ); ok( true, "Browser doesn't support scroll position." );
} else { } else {
equals( jQuery(win).scrollTop(), 1000, "jQuery(window).scrollTop()" ); equal( jQuery(win).scrollTop(), 1000, "jQuery(window).scrollTop()" );
equals( jQuery(win).scrollLeft(), 1000, "jQuery(window).scrollLeft()" ); equal( jQuery(win).scrollLeft(), 1000, "jQuery(window).scrollLeft()" );
equals( jQuery(win.document).scrollTop(), 1000, "jQuery(document).scrollTop()" ); equal( jQuery(win.document).scrollTop(), 1000, "jQuery(document).scrollTop()" );
equals( jQuery(win.document).scrollLeft(), 1000, "jQuery(document).scrollLeft()" ); equal( jQuery(win.document).scrollLeft(), 1000, "jQuery(document).scrollLeft()" );
} }
// test jQuery using parent window/document // test jQuery using parent window/document
// jQuery reference here is in the iframe // jQuery reference here is in the iframe
window.scrollTo(0,0); window.scrollTo(0,0);
equals( jQuery(window).scrollTop(), 0, "jQuery(window).scrollTop() other window" ); equal( jQuery(window).scrollTop(), 0, "jQuery(window).scrollTop() other window" );
equals( jQuery(window).scrollLeft(), 0, "jQuery(window).scrollLeft() other window" ); equal( jQuery(window).scrollLeft(), 0, "jQuery(window).scrollLeft() other window" );
equals( jQuery(document).scrollTop(), 0, "jQuery(window).scrollTop() other document" ); equal( jQuery(document).scrollTop(), 0, "jQuery(window).scrollTop() other document" );
equals( jQuery(document).scrollLeft(), 0, "jQuery(window).scrollLeft() other document" ); equal( jQuery(document).scrollLeft(), 0, "jQuery(window).scrollLeft() other document" );
// Tests scrollTop/Left with empty jquery objects // Tests scrollTop/Left with empty jquery objects
notEqual( jQuery().scrollTop(100), null, "jQuery().scrollTop(100) testing setter on empty jquery object" ); notEqual( jQuery().scrollTop(100), null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
...@@ -401,42 +401,42 @@ testoffset("scroll", function( jQuery, win ) { ...@@ -401,42 +401,42 @@ testoffset("scroll", function( jQuery, win ) {
testoffset("body", function( jQuery ) { testoffset("body", function( jQuery ) {
expect(2); expect(2);
equals( jQuery("body").offset().top, 1, "jQuery('#body').offset().top" ); equal( jQuery("body").offset().top, 1, "jQuery('#body').offset().top" );
equals( jQuery("body").offset().left, 1, "jQuery('#body').offset().left" ); equal( jQuery("body").offset().left, 1, "jQuery('#body').offset().left" );
}); });
test("Chaining offset(coords) returns jQuery object", function() { test("Chaining offset(coords) returns jQuery object", function() {
expect(2); expect(2);
var coords = { top: 1, left: 1 }; var coords = { top: 1, left: 1 };
equals( jQuery("#absolute-1").offset(coords).selector, "#absolute-1", "offset(coords) returns jQuery object" ); equal( jQuery("#absolute-1").offset(coords).selector, "#absolute-1", "offset(coords) returns jQuery object" );
equals( jQuery("#non-existent").offset(coords).selector, "#non-existent", "offset(coords) with empty jQuery set returns jQuery object" ); equal( jQuery("#non-existent").offset(coords).selector, "#non-existent", "offset(coords) with empty jQuery set returns jQuery object" );
}); });
test("offsetParent", function(){ test("offsetParent", function(){
expect(11); expect(11);
var body = jQuery("body").offsetParent(); var body = jQuery("body").offsetParent();
equals( body.length, 1, "Only one offsetParent found." ); equal( body.length, 1, "Only one offsetParent found." );
equals( body[0], document.body, "The body is its own offsetParent." ); equal( body[0], document.body, "The body is its own offsetParent." );
var header = jQuery("#qunit-header").offsetParent(); var header = jQuery("#qunit-header").offsetParent();
equals( header.length, 1, "Only one offsetParent found." ); equal( header.length, 1, "Only one offsetParent found." );
equals( header[0], document.body, "The body is the offsetParent." ); equal( header[0], document.body, "The body is the offsetParent." );
var div = jQuery("#nothiddendivchild").offsetParent(); var div = jQuery("#nothiddendivchild").offsetParent();
equals( div.length, 1, "Only one offsetParent found." ); equal( div.length, 1, "Only one offsetParent found." );
equals( div[0], document.body, "The body is the offsetParent." ); equal( div[0], document.body, "The body is the offsetParent." );
jQuery("#nothiddendiv").css("position", "relative"); jQuery("#nothiddendiv").css("position", "relative");
div = jQuery("#nothiddendivchild").offsetParent(); div = jQuery("#nothiddendivchild").offsetParent();
equals( div.length, 1, "Only one offsetParent found." ); equal( div.length, 1, "Only one offsetParent found." );
equals( div[0], jQuery("#nothiddendiv")[0], "The div is the offsetParent." ); equal( div[0], jQuery("#nothiddendiv")[0], "The div is the offsetParent." );
div = jQuery("body, #nothiddendivchild").offsetParent(); div = jQuery("body, #nothiddendivchild").offsetParent();
equals( div.length, 2, "Two offsetParent found." ); equal( div.length, 2, "Two offsetParent found." );
equals( div[0], document.body, "The body is the offsetParent." ); equal( div[0], document.body, "The body is the offsetParent." );
equals( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." ); equal( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." );
}); });
test("fractions (see #7730 and #7885)", function() { test("fractions (see #7730 and #7885)", function() {
...@@ -459,8 +459,8 @@ test("fractions (see #7730 and #7885)", function() { ...@@ -459,8 +459,8 @@ test("fractions (see #7730 and #7885)", function() {
var result = div.offset(); var result = div.offset();
equals( result.top, expected.top, "Check top" ); equal( result.top, expected.top, "Check top" );
equals( result.left, expected.left, "Check left" ); equal( result.left, expected.left, "Check left" );
div.remove(); div.remove();
}); });
......
...@@ -10,41 +10,41 @@ test("queue() with other types",function() { ...@@ -10,41 +10,41 @@ test("queue() with other types",function() {
defer; defer;
$div.promise("foo").done(function() { $div.promise("foo").done(function() {
equals( counter, 0, "Deferred for collection with no queue is automatically resolved" ); equal( counter, 0, "Deferred for collection with no queue is automatically resolved" );
}); });
$div $div
.queue("foo",function(){ .queue("foo",function(){
equals( ++counter, 1, "Dequeuing" ); equal( ++counter, 1, "Dequeuing" );
jQuery.dequeue(this,"foo"); jQuery.dequeue(this,"foo");
}) })
.queue("foo",function(){ .queue("foo",function(){
equals( ++counter, 2, "Dequeuing" ); equal( ++counter, 2, "Dequeuing" );
jQuery(this).dequeue("foo"); jQuery(this).dequeue("foo");
}) })
.queue("foo",function(){ .queue("foo",function(){
equals( ++counter, 3, "Dequeuing" ); equal( ++counter, 3, "Dequeuing" );
}) })
.queue("foo",function(){ .queue("foo",function(){
equals( ++counter, 4, "Dequeuing" ); equal( ++counter, 4, "Dequeuing" );
}); });
defer = $div.promise("foo").done(function() { defer = $div.promise("foo").done(function() {
equals( counter, 4, "Testing previous call to dequeue in deferred" ); equal( counter, 4, "Testing previous call to dequeue in deferred" );
start(); start();
}); });
equals( $div.queue("foo").length, 4, "Testing queue length" ); equal( $div.queue("foo").length, 4, "Testing queue length" );
$div.dequeue("foo"); $div.dequeue("foo");
equals( counter, 3, "Testing previous call to dequeue" ); equal( counter, 3, "Testing previous call to dequeue" );
equals( $div.queue("foo").length, 1, "Testing queue length" ); equal( $div.queue("foo").length, 1, "Testing queue length" );
$div.dequeue("foo"); $div.dequeue("foo");
equals( counter, 4, "Testing previous call to dequeue" ); equal( counter, 4, "Testing previous call to dequeue" );
equals( $div.queue("foo").length, 0, "Testing queue length" ); equal( $div.queue("foo").length, 0, "Testing queue length" );
}); });
test("queue(name) passes in the next item in the queue as a parameter", function() { test("queue(name) passes in the next item in the queue as a parameter", function() {
...@@ -54,13 +54,13 @@ test("queue(name) passes in the next item in the queue as a parameter", function ...@@ -54,13 +54,13 @@ test("queue(name) passes in the next item in the queue as a parameter", function
var counter = 0; var counter = 0;
div.queue("foo", function(next) { div.queue("foo", function(next) {
equals(++counter, 1, "Dequeueing"); equal(++counter, 1, "Dequeueing");
next(); next();
}).queue("foo", function(next) { }).queue("foo", function(next) {
equals(++counter, 2, "Next was called"); equal(++counter, 2, "Next was called");
next(); next();
}).queue("bar", function() { }).queue("bar", function() {
equals(++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");
...@@ -74,18 +74,18 @@ test("queue() passes in the next item in the queue as a parameter to fx queues", ...@@ -74,18 +74,18 @@ test("queue() passes in the next item in the queue as a parameter to fx queues",
var counter = 0; var counter = 0;
div.queue(function(next) { div.queue(function(next) {
equals(++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) {
equals(++counter, 2, "Next was called"); equal(++counter, 2, "Next was called");
next(); next();
}).queue("bar", function() { }).queue("bar", function() {
equals(++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() {
equals(counter, 2, "Deferreds resolved"); equal(counter, 2, "Deferreds resolved");
start(); start();
}); });
}); });
...@@ -110,7 +110,7 @@ test("callbacks keep their place in the queue", function() { ...@@ -110,7 +110,7 @@ test("callbacks keep their place in the queue", function() {
}); });
div.promise("fx").done(function() { div.promise("fx").done(function() {
equals(counter, 4, "Deferreds resolved"); equal(counter, 4, "Deferreds resolved");
start(); start();
}); });
}); });
...@@ -127,7 +127,7 @@ test("delay()", function() { ...@@ -127,7 +127,7 @@ test("delay()", function() {
start(); start();
}); });
equals( run, 0, "The delay delayed the next function from running." ); equal( run, 0, "The delay delayed the next function from running." );
}); });
test("delay() can be stopped", function() { test("delay() can be stopped", function() {
...@@ -191,7 +191,7 @@ test("clearQueue(name) clears the queue", function() { ...@@ -191,7 +191,7 @@ test("clearQueue(name) clears the queue", function() {
div.dequeue("foo"); div.dequeue("foo");
equals(counter, 1, "the queue was cleared"); equal(counter, 1, "the queue was cleared");
}); });
test("clearQueue() clears the fx queue", function() { test("clearQueue() clears the fx queue", function() {
...@@ -208,7 +208,7 @@ test("clearQueue() clears the fx queue", function() { ...@@ -208,7 +208,7 @@ test("clearQueue() clears the fx queue", function() {
counter++; counter++;
}); });
equals(counter, 1, "the queue was cleared"); equal(counter, 1, "the queue was cleared");
div.removeData(); div.removeData();
}); });
......
...@@ -2,15 +2,15 @@ module("traversing", { teardown: moduleTeardown }); ...@@ -2,15 +2,15 @@ module("traversing", { teardown: moduleTeardown });
test("find(String)", function() { test("find(String)", function() {
expect(5); expect(5);
equals( "Yahoo", jQuery("#foo").find(".blogTest").text(), "Check for find" ); equal( "Yahoo", jQuery("#foo").find(".blogTest").text(), "Check for find" );
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents(); var j = jQuery("#nonnodes").contents();
equals( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" ); equal( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" );
same( jQuery("#qunit-fixture").find("> div").get(), q("foo", "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest"), "find child elements" ); deepEqual( jQuery("#qunit-fixture").find("> div").get(), q("foo", "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest"), "find child elements" );
same( jQuery("#qunit-fixture").find("> #foo, > #moretests").get(), q("foo", "moretests"), "find child elements" ); deepEqual( jQuery("#qunit-fixture").find("> #foo, > #moretests").get(), q("foo", "moretests"), "find child elements" );
same( jQuery("#qunit-fixture").find("> #foo > p").get(), q("sndp", "en", "sap"), "find child elements" ); deepEqual( jQuery("#qunit-fixture").find("> #foo > p").get(), q("sndp", "en", "sap"), "find child elements" );
}); });
test("find(node|jQuery object)", function() { test("find(node|jQuery object)", function() {
...@@ -22,18 +22,18 @@ test("find(node|jQuery object)", function() { ...@@ -22,18 +22,18 @@ test("find(node|jQuery object)", function() {
$two = $blog.add( $first ), $two = $blog.add( $first ),
$fooTwo = $foo.add( $blog ); $fooTwo = $foo.add( $blog );
equals( $foo.find( $blog ).text(), "Yahoo", "Find with blog jQuery object" ); equal( $foo.find( $blog ).text(), "Yahoo", "Find with blog jQuery object" );
equals( $foo.find( $blog[0] ).text(), "Yahoo", "Find with blog node" ); equal( $foo.find( $blog[0] ).text(), "Yahoo", "Find with blog node" );
equals( $foo.find( $first ).length, 0, "#first is not in #foo" ); equal( $foo.find( $first ).length, 0, "#first is not in #foo" );
equals( $foo.find( $first[0]).length, 0, "#first not in #foo (node)" ); equal( $foo.find( $first[0]).length, 0, "#first not in #foo (node)" );
ok( $foo.find( $two ).is(".blogTest"), "Find returns only nodes within #foo" ); ok( $foo.find( $two ).is(".blogTest"), "Find returns only nodes within #foo" );
ok( $fooTwo.find( $blog ).is(".blogTest"), "Blog is part of the collection, but also within foo" ); ok( $fooTwo.find( $blog ).is(".blogTest"), "Blog is part of the collection, but also within foo" );
ok( $fooTwo.find( $blog[0] ).is(".blogTest"), "Blog is part of the collection, but also within foo(node)" ); ok( $fooTwo.find( $blog[0] ).is(".blogTest"), "Blog is part of the collection, but also within foo(node)" );
equals( $two.find( $foo ).length, 0, "Foo is not in two elements" ); equal( $two.find( $foo ).length, 0, "Foo is not in two elements" );
equals( $two.find( $foo[0] ).length, 0, "Foo is not in two elements(node)" ); equal( $two.find( $foo[0] ).length, 0, "Foo is not in two elements(node)" );
equals( $two.find( $first ).length, 0, "first is in the collection and not within two" ); equal( $two.find( $first ).length, 0, "first is in the collection and not within two" );
equals( $two.find( $first ).length, 0, "first is in the collection and not within two(node)" ); equal( $two.find( $first ).length, 0, "first is in the collection and not within two(node)" );
}); });
...@@ -156,74 +156,74 @@ test("index(Object|String|undefined)", function() { ...@@ -156,74 +156,74 @@ test("index(Object|String|undefined)", function() {
inputElements = jQuery("#radio1,#radio2,#check1,#check2"); inputElements = jQuery("#radio1,#radio2,#check1,#check2");
// Passing a node // Passing a node
equals( elements.index(window), 0, "Check for index of elements" ); equal( elements.index(window), 0, "Check for index of elements" );
equals( elements.index(document), 1, "Check for index of elements" ); equal( elements.index(document), 1, "Check for index of elements" );
equals( inputElements.index(document.getElementById("radio1")), 0, "Check for index of elements" ); equal( inputElements.index(document.getElementById("radio1")), 0, "Check for index of elements" );
equals( inputElements.index(document.getElementById("radio2")), 1, "Check for index of elements" ); equal( inputElements.index(document.getElementById("radio2")), 1, "Check for index of elements" );
equals( inputElements.index(document.getElementById("check1")), 2, "Check for index of elements" ); equal( inputElements.index(document.getElementById("check1")), 2, "Check for index of elements" );
equals( inputElements.index(document.getElementById("check2")), 3, "Check for index of elements" ); equal( inputElements.index(document.getElementById("check2")), 3, "Check for index of elements" );
equals( inputElements.index(window), -1, "Check for not found index" ); equal( inputElements.index(window), -1, "Check for not found index" );
equals( inputElements.index(document), -1, "Check for not found index" ); equal( inputElements.index(document), -1, "Check for not found index" );
// Passing a jQuery object // Passing a jQuery object
// enabled since [5500] // enabled since [5500]
equals( elements.index( elements ), 0, "Pass in a jQuery object" ); equal( elements.index( elements ), 0, "Pass in a jQuery object" );
equals( elements.index( elements.eq(1) ), 1, "Pass in a jQuery object" ); equal( elements.index( elements.eq(1) ), 1, "Pass in a jQuery object" );
equals( jQuery("#form :radio").index( jQuery("#radio2") ), 1, "Pass in a jQuery object" ); equal( jQuery("#form :radio").index( jQuery("#radio2") ), 1, "Pass in a jQuery object" );
// Passing a selector or nothing // Passing a selector or nothing
// enabled since [6330] // enabled since [6330]
equals( jQuery("#text2").index(), 2, "Check for index amongst siblings" ); equal( jQuery("#text2").index(), 2, "Check for index amongst siblings" );
equals( jQuery("#form").children().eq(4).index(), 4, "Check for index amongst siblings" ); equal( jQuery("#form").children().eq(4).index(), 4, "Check for index amongst siblings" );
equals( jQuery("#radio2").index("#form :radio") , 1, "Check for index within a selector" ); equal( jQuery("#radio2").index("#form :radio") , 1, "Check for index within a selector" );
equals( jQuery("#form :radio").index( jQuery("#radio2") ), 1, "Check for index within a selector" ); equal( jQuery("#form :radio").index( jQuery("#radio2") ), 1, "Check for index within a selector" );
equals( jQuery("#radio2").index("#form :text") , -1, "Check for index not found within a selector" ); equal( jQuery("#radio2").index("#form :text") , -1, "Check for index not found within a selector" );
}); });
test("filter(Selector|undefined)", function() { test("filter(Selector|undefined)", function() {
expect(9); expect(9);
same( jQuery("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" ); deepEqual( jQuery("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
same( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" ); deepEqual( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
same( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" ); deepEqual( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
same( jQuery("p").filter(null).get(), [], "filter(null) should return an empty jQuery object"); deepEqual( jQuery("p").filter(null).get(), [], "filter(null) should return an empty jQuery object");
same( jQuery("p").filter(undefined).get(), [], "filter(undefined) should return an empty jQuery object"); deepEqual( jQuery("p").filter(undefined).get(), [], "filter(undefined) should return an empty jQuery object");
same( jQuery("p").filter(0).get(), [], "filter(0) should return an empty jQuery object"); deepEqual( jQuery("p").filter(0).get(), [], "filter(0) should return an empty jQuery object");
same( jQuery("p").filter("").get(), [], "filter('') should return an empty jQuery object"); deepEqual( jQuery("p").filter("").get(), [], "filter('') should return an empty jQuery object");
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents(); var j = jQuery("#nonnodes").contents();
equals( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" ); equal( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" );
equals( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" ); equal( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" );
}); });
test("filter(Function)", function() { test("filter(Function)", function() {
expect(2); expect(2);
same( 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)" );
same( 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() {
expect(1); expect(1);
var element = document.getElementById("text1"); var element = document.getElementById("text1");
same( jQuery("#form input").filter(element).get(), q("text1"), "filter(Element)" ); deepEqual( jQuery("#form input").filter(element).get(), q("text1"), "filter(Element)" );
}); });
test("filter(Array)", function() { test("filter(Array)", function() {
expect(1); expect(1);
var elements = [ document.getElementById("text1") ]; var elements = [ document.getElementById("text1") ];
same( jQuery("#form input").filter(elements).get(), q("text1"), "filter(Element)" ); deepEqual( jQuery("#form input").filter(elements).get(), q("text1"), "filter(Element)" );
}); });
test("filter(jQuery)", function() { test("filter(jQuery)", function() {
expect(1); expect(1);
var elements = jQuery("#text1"); var elements = jQuery("#text1");
same( jQuery("#form input").filter(elements).get(), q("text1"), "filter(Element)" ); deepEqual( jQuery("#form input").filter(elements).get(), q("text1"), "filter(Element)" );
}); });
...@@ -272,41 +272,41 @@ test("filter() with positional selectors", function() { ...@@ -272,41 +272,41 @@ test("filter() with positional selectors", function() {
test("closest()", function() { test("closest()", function() {
expect(13); expect(13);
same( jQuery("body").closest("body").get(), q("body"), "closest(body)" ); deepEqual( jQuery("body").closest("body").get(), q("body"), "closest(body)" );
same( jQuery("body").closest("html").get(), q("html"), "closest(html)" ); deepEqual( jQuery("body").closest("html").get(), q("html"), "closest(html)" );
same( jQuery("body").closest("div").get(), [], "closest(div)" ); deepEqual( jQuery("body").closest("div").get(), [], "closest(div)" );
same( jQuery("#qunit-fixture").closest("span,#html").get(), q("html"), "closest(span,#html)" ); deepEqual( jQuery("#qunit-fixture").closest("span,#html").get(), q("html"), "closest(span,#html)" );
same( jQuery("div:eq(1)").closest("div:first").get(), [], "closest(div:first)" ); deepEqual( jQuery("div:eq(1)").closest("div:first").get(), [], "closest(div:first)" );
same( jQuery("div").closest("body:first div:last").get(), q("fx-tests"), "closest(body:first div:last)" ); deepEqual( jQuery("div").closest("body:first div:last").get(), q("fx-tests"), "closest(body:first div:last)" );
// Test .closest() limited by the context // Test .closest() limited by the context
var jq = jQuery("#nothiddendivchild"); var jq = jQuery("#nothiddendivchild");
same( jq.closest("html", document.body).get(), [], "Context limited." ); deepEqual( jq.closest("html", document.body).get(), [], "Context limited." );
same( jq.closest("body", document.body).get(), [], "Context limited." ); deepEqual( jq.closest("body", document.body).get(), [], "Context limited." );
same( jq.closest("#nothiddendiv", document.body).get(), q("nothiddendiv"), "Context not reached." ); deepEqual( jq.closest("#nothiddendiv", document.body).get(), q("nothiddendiv"), "Context not reached." );
//Test that .closest() returns unique'd set //Test that .closest() returns unique'd set
equals( jQuery("#qunit-fixture p").closest("#qunit-fixture").length, 1, "Closest should return a unique set" ); equal( jQuery("#qunit-fixture p").closest("#qunit-fixture").length, 1, "Closest should return a unique set" );
// Test on disconnected node // Test on disconnected node
equals( jQuery("<div><p></p></div>").find("p").closest("table").length, 0, "Make sure disconnected closest work." ); equal( jQuery("<div><p></p></div>").find("p").closest("table").length, 0, "Make sure disconnected closest work." );
// Bug #7369 // Bug #7369
equals( jQuery("<div foo='bar'></div>").closest("[foo]").length, 1, "Disconnected nodes with attribute selector" ); equal( jQuery("<div foo='bar'></div>").closest("[foo]").length, 1, "Disconnected nodes with attribute selector" );
equals( jQuery("<div>text</div>").closest("[lang]").length, 0, "Disconnected nodes with text and non-existent attribute selector" ); equal( jQuery("<div>text</div>").closest("[lang]").length, 0, "Disconnected nodes with text and non-existent attribute selector" );
}); });
test("closest(Array)", function() { test("closest(Array)", function() {
expect(7); expect(7);
same( jQuery("body").closest(["body"]), [{selector:"body", elem:document.body, level:1}], "closest([body])" ); deepEqual( jQuery("body").closest(["body"]), [{selector:"body", elem:document.body, level:1}], "closest([body])" );
same( jQuery("body").closest(["html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([html])" ); deepEqual( jQuery("body").closest(["html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([html])" );
same( jQuery("body").closest(["div"]), [], "closest([div])" ); deepEqual( jQuery("body").closest(["div"]), [], "closest([div])" );
same( jQuery("#yahoo").closest(["div"]), [{"selector":"div", "elem": document.getElementById("foo"), "level": 3}, { "selector": "div", "elem": document.getElementById("qunit-fixture"), "level": 4 }], "closest([div])" ); deepEqual( jQuery("#yahoo").closest(["div"]), [{"selector":"div", "elem": document.getElementById("foo"), "level": 3}, { "selector": "div", "elem": document.getElementById("qunit-fixture"), "level": 4 }], "closest([div])" );
same( jQuery("#qunit-fixture").closest(["span,#html"]), [{selector:"span,#html", elem:document.documentElement, level:4}], "closest([span,#html])" ); deepEqual( jQuery("#qunit-fixture").closest(["span,#html"]), [{selector:"span,#html", elem:document.documentElement, level:4}], "closest([span,#html])" );
same( jQuery("body").closest(["body","html"]), [{selector:"body", elem:document.body, level:1}, {selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" ); deepEqual( jQuery("body").closest(["body","html"]), [{selector:"body", elem:document.body, level:1}, {selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" );
same( jQuery("body").closest(["span","html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" ); deepEqual( jQuery("body").closest(["span","html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" );
}); });
test("closest(jQuery)", function() { test("closest(jQuery)", function() {
...@@ -319,132 +319,132 @@ test("closest(jQuery)", function() { ...@@ -319,132 +319,132 @@ test("closest(jQuery)", function() {
ok( $child.closest( $parent[0] ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') ) :: node" ); ok( $child.closest( $parent[0] ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') ) :: node" );
ok( $child.closest( $child ).is("#nothiddendivchild"), "child is included" ); ok( $child.closest( $child ).is("#nothiddendivchild"), "child is included" );
ok( $child.closest( $child[0] ).is("#nothiddendivchild"), "child is included :: node" ); ok( $child.closest( $child[0] ).is("#nothiddendivchild"), "child is included :: node" );
equals( $child.closest( document.createElement("div") ).length, 0, "created element is not related" ); equal( $child.closest( document.createElement("div") ).length, 0, "created element is not related" );
equals( $child.closest( $main ).length, 0, "Main not a parent of child" ); equal( $child.closest( $main ).length, 0, "Main not a parent of child" );
equals( $child.closest( $main[0] ).length, 0, "Main not a parent of child :: node" ); equal( $child.closest( $main[0] ).length, 0, "Main not a parent of child :: node" );
ok( $child.closest( $body.add($parent) ).is("#nothiddendiv"), "Closest ancestor retrieved." ); ok( $child.closest( $body.add($parent) ).is("#nothiddendiv"), "Closest ancestor retrieved." );
}); });
test("not(Selector|undefined)", function() { test("not(Selector|undefined)", function() {
expect(11); expect(11);
equals( jQuery("#qunit-fixture > p#ap > a").not("#google").length, 2, "not('selector')" ); equal( jQuery("#qunit-fixture > p#ap > a").not("#google").length, 2, "not('selector')" );
same( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" ); deepEqual( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
same( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" ); deepEqual( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
same( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d", "option3e", "option4e","option5b"), "not('complex selector')"); deepEqual( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d", "option3e", "option4e","option5b"), "not('complex selector')");
same( jQuery("#ap *").not("code").get(), q("google", "groups", "anchor1", "mark"), "not('tag selector')" ); deepEqual( jQuery("#ap *").not("code").get(), q("google", "groups", "anchor1", "mark"), "not('tag selector')" );
same( jQuery("#ap *").not("code, #mark").get(), q("google", "groups", "anchor1"), "not('tag, ID selector')" ); deepEqual( jQuery("#ap *").not("code, #mark").get(), q("google", "groups", "anchor1"), "not('tag, ID selector')" );
same( jQuery("#ap *").not("#mark, code").get(), q("google", "groups", "anchor1"), "not('ID, tag selector')"); deepEqual( jQuery("#ap *").not("#mark, code").get(), q("google", "groups", "anchor1"), "not('ID, tag selector')");
var all = jQuery("p").get(); var all = jQuery("p").get();
same( jQuery("p").not(null).get(), all, "not(null) should have no effect"); deepEqual( jQuery("p").not(null).get(), all, "not(null) should have no effect");
same( jQuery("p").not(undefined).get(), all, "not(undefined) should have no effect"); deepEqual( jQuery("p").not(undefined).get(), all, "not(undefined) should have no effect");
same( jQuery("p").not(0).get(), all, "not(0) should have no effect"); deepEqual( jQuery("p").not(0).get(), all, "not(0) should have no effect");
same( jQuery("p").not("").get(), all, "not('') should have no effect"); deepEqual( jQuery("p").not("").get(), all, "not('') should have no effect");
}); });
test("not(Element)", function() { test("not(Element)", function() {
expect(1); expect(1);
var selects = jQuery("#form select"); var selects = jQuery("#form select");
same( selects.not( selects[1] ).get(), q("select1", "select3", "select4", "select5"), "filter out DOM element"); deepEqual( selects.not( selects[1] ).get(), q("select1", "select3", "select4", "select5"), "filter out DOM element");
}); });
test("not(Function)", function() { test("not(Function)", function() {
same( 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() {
expect(2); expect(2);
equals( jQuery("#qunit-fixture > p#ap > a").not(document.getElementById("google")).length, 2, "not(DOMElement)" ); equal( jQuery("#qunit-fixture > p#ap > a").not(document.getElementById("google")).length, 2, "not(DOMElement)" );
equals( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" ); equal( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" );
}); });
test("not(jQuery)", function() { test("not(jQuery)", function() {
expect(1); expect(1);
same( jQuery("p").not(jQuery("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" ); deepEqual( jQuery("p").not(jQuery("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
}); });
test("has(Element)", function() { test("has(Element)", function() {
expect(2); expect(2);
var obj = jQuery("#qunit-fixture").has(jQuery("#sndp")[0]); var obj = jQuery("#qunit-fixture").has(jQuery("#sndp")[0]);
same( obj.get(), q("qunit-fixture"), "Keeps elements that have the element as a descendant" ); deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have the element as a descendant" );
var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")[0]); var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")[0]);
same( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" ); deepEqual( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
}); });
test("has(Selector)", function() { test("has(Selector)", function() {
expect(3); expect(3);
var obj = jQuery("#qunit-fixture").has("#sndp"); var obj = jQuery("#qunit-fixture").has("#sndp");
same( obj.get(), q("qunit-fixture"), "Keeps elements that have any element matching the selector as a descendant" ); deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have any element matching the selector as a descendant" );
var multipleParent = jQuery("#qunit-fixture, #header").has("#sndp"); var multipleParent = jQuery("#qunit-fixture, #header").has("#sndp");
same( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" ); deepEqual( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
var multipleHas = jQuery("#qunit-fixture").has("#sndp, #first"); var multipleHas = jQuery("#qunit-fixture").has("#sndp, #first");
same( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" ); deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" );
}); });
test("has(Arrayish)", function() { test("has(Arrayish)", function() {
expect(3); expect(3);
var simple = jQuery("#qunit-fixture").has(jQuery("#sndp")); var simple = jQuery("#qunit-fixture").has(jQuery("#sndp"));
same( simple.get(), q("qunit-fixture"), "Keeps elements that have any element in the jQuery list as a descendant" ); deepEqual( simple.get(), q("qunit-fixture"), "Keeps elements that have any element in the jQuery list as a descendant" );
var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")); var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp"));
same( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have an element in the jQuery list as a descendant" ); deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have an element in the jQuery list as a descendant" );
var multipleHas = jQuery("#qunit-fixture").has(jQuery("#sndp, #first")); var multipleHas = jQuery("#qunit-fixture").has(jQuery("#sndp, #first"));
same( simple.get(), q("qunit-fixture"), "Only adds elements once" ); deepEqual( simple.get(), q("qunit-fixture"), "Only adds elements once" );
}); });
test("andSelf()", function() { test("andSelf()", function() {
expect(4); expect(4);
same( jQuery("#en").siblings().andSelf().get(), q("sndp", "en", "sap"), "Check for siblings and self" ); deepEqual( jQuery("#en").siblings().andSelf().get(), q("sndp", "en", "sap"), "Check for siblings and self" );
same( jQuery("#foo").children().andSelf().get(), q("foo", "sndp", "en", "sap"), "Check for children and self" ); deepEqual( jQuery("#foo").children().andSelf().get(), q("foo", "sndp", "en", "sap"), "Check for children and self" );
same( jQuery("#sndp, #en").parent().andSelf().get(), q("foo","sndp","en"), "Check for parent and self" ); deepEqual( jQuery("#sndp, #en").parent().andSelf().get(), q("foo","sndp","en"), "Check for parent and self" );
same( jQuery("#groups").parents("p, div").andSelf().get(), q("qunit-fixture", "ap", "groups"), "Check for parents and self" ); deepEqual( jQuery("#groups").parents("p, div").andSelf().get(), q("qunit-fixture", "ap", "groups"), "Check for parents and self" );
}); });
test("siblings([String])", function() { test("siblings([String])", function() {
expect(6); expect(6);
same( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" ); deepEqual( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
same( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" ); deepEqual( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" );
same( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" ); deepEqual( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
same( jQuery("#foo").siblings("form, b").get(), q("form", "floatTest", "lengthtest", "name-tests", "testForm"), "Check for multiple filters" ); deepEqual( jQuery("#foo").siblings("form, b").get(), q("form", "floatTest", "lengthtest", "name-tests", "testForm"), "Check for multiple filters" );
var set = q("sndp", "en", "sap"); var set = q("sndp", "en", "sap");
same( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" ); deepEqual( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" );
deepEqual( jQuery("#option5a").siblings("option[data-attr]").get(), q("option5c"), "Has attribute selector in siblings (#9261)" ); deepEqual( jQuery("#option5a").siblings("option[data-attr]").get(), q("option5c"), "Has attribute selector in siblings (#9261)" );
}); });
test("children([String])", function() { test("children([String])", function() {
expect(3); expect(3);
same( jQuery("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" ); deepEqual( jQuery("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
same( jQuery("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" ); deepEqual( jQuery("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" );
same( jQuery("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" ); deepEqual( jQuery("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
}); });
test("parent([String])", function() { test("parent([String])", function() {
expect(5); expect(5);
equals( jQuery("#groups").parent()[0].id, "ap", "Simple parent check" ); equal( jQuery("#groups").parent()[0].id, "ap", "Simple parent check" );
equals( jQuery("#groups").parent("p")[0].id, "ap", "Filtered parent check" ); equal( jQuery("#groups").parent("p")[0].id, "ap", "Filtered parent check" );
equals( jQuery("#groups").parent("div").length, 0, "Filtered parent check, no match" ); equal( jQuery("#groups").parent("div").length, 0, "Filtered parent check, no match" );
equals( jQuery("#groups").parent("div, p")[0].id, "ap", "Check for multiple filters" ); equal( jQuery("#groups").parent("div, p")[0].id, "ap", "Check for multiple filters" );
same( jQuery("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" ); deepEqual( jQuery("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" );
}); });
test("parents([String])", function() { test("parents([String])", function() {
expect(5); expect(5);
equals( jQuery("#groups").parents()[0].id, "ap", "Simple parents check" ); equal( jQuery("#groups").parents()[0].id, "ap", "Simple parents check" );
equals( jQuery("#groups").parents("p")[0].id, "ap", "Filtered parents check" ); equal( jQuery("#groups").parents("p")[0].id, "ap", "Filtered parents check" );
equals( jQuery("#groups").parents("div")[0].id, "qunit-fixture", "Filtered parents check2" ); equal( jQuery("#groups").parents("div")[0].id, "qunit-fixture", "Filtered parents check2" );
same( jQuery("#groups").parents("p, div").get(), q("ap", "qunit-fixture"), "Check for multiple filters" ); deepEqual( jQuery("#groups").parents("p, div").get(), q("ap", "qunit-fixture"), "Check for multiple filters" );
same( jQuery("#en, #sndp").parents().get(), q("foo", "qunit-fixture", "dl", "body", "html"), "Check for unique results from parents" ); deepEqual( jQuery("#en, #sndp").parents().get(), q("foo", "qunit-fixture", "dl", "body", "html"), "Check for unique results from parents" );
}); });
test("parentsUntil([String])", function() { test("parentsUntil([String])", function() {
...@@ -452,31 +452,31 @@ test("parentsUntil([String])", function() { ...@@ -452,31 +452,31 @@ test("parentsUntil([String])", function() {
var parents = jQuery("#groups").parents(); var parents = jQuery("#groups").parents();
same( jQuery("#groups").parentsUntil().get(), parents.get(), "parentsUntil with no selector (nextAll)" ); deepEqual( jQuery("#groups").parentsUntil().get(), parents.get(), "parentsUntil with no selector (nextAll)" );
same( jQuery("#groups").parentsUntil(".foo").get(), parents.get(), "parentsUntil with invalid selector (nextAll)" ); deepEqual( jQuery("#groups").parentsUntil(".foo").get(), parents.get(), "parentsUntil with invalid selector (nextAll)" );
same( jQuery("#groups").parentsUntil("#html").get(), parents.not(":last").get(), "Simple parentsUntil check" ); deepEqual( jQuery("#groups").parentsUntil("#html").get(), parents.not(":last").get(), "Simple parentsUntil check" );
equals( jQuery("#groups").parentsUntil("#ap").length, 0, "Simple parentsUntil check" ); equal( jQuery("#groups").parentsUntil("#ap").length, 0, "Simple parentsUntil check" );
same( jQuery("#groups").parentsUntil("#html, #body").get(), parents.slice( 0, 3 ).get(), "Less simple parentsUntil check" ); deepEqual( jQuery("#groups").parentsUntil("#html, #body").get(), parents.slice( 0, 3 ).get(), "Less simple parentsUntil check" );
same( jQuery("#groups").parentsUntil("#html", "div").get(), jQuery("#qunit-fixture").get(), "Filtered parentsUntil check" ); deepEqual( jQuery("#groups").parentsUntil("#html", "div").get(), jQuery("#qunit-fixture").get(), "Filtered parentsUntil check" );
same( jQuery("#groups").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multiple-filtered parentsUntil check" ); deepEqual( jQuery("#groups").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multiple-filtered parentsUntil check" );
equals( jQuery("#groups").parentsUntil("#html", "span").length, 0, "Filtered parentsUntil check, no match" ); equal( jQuery("#groups").parentsUntil("#html", "span").length, 0, "Filtered parentsUntil check, no match" );
same( jQuery("#groups, #ap").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multi-source, multiple-filtered parentsUntil check" ); deepEqual( jQuery("#groups, #ap").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multi-source, multiple-filtered parentsUntil check" );
}); });
test("next([String])", function() { test("next([String])", function() {
expect(4); expect(4);
equals( jQuery("#ap").next()[0].id, "foo", "Simple next check" ); equal( jQuery("#ap").next()[0].id, "foo", "Simple next check" );
equals( jQuery("#ap").next("div")[0].id, "foo", "Filtered next check" ); equal( jQuery("#ap").next("div")[0].id, "foo", "Filtered next check" );
equals( jQuery("#ap").next("p").length, 0, "Filtered next check, no match" ); equal( jQuery("#ap").next("p").length, 0, "Filtered next check, no match" );
equals( jQuery("#ap").next("div, p")[0].id, "foo", "Multiple filters" ); equal( jQuery("#ap").next("div, p")[0].id, "foo", "Multiple filters" );
}); });
test("prev([String])", function() { test("prev([String])", function() {
expect(4); expect(4);
equals( jQuery("#foo").prev()[0].id, "ap", "Simple prev check" ); equal( jQuery("#foo").prev()[0].id, "ap", "Simple prev check" );
equals( jQuery("#foo").prev("p")[0].id, "ap", "Filtered prev check" ); equal( jQuery("#foo").prev("p")[0].id, "ap", "Filtered prev check" );
equals( jQuery("#foo").prev("div").length, 0, "Filtered prev check, no match" ); equal( jQuery("#foo").prev("div").length, 0, "Filtered prev check, no match" );
equals( jQuery("#foo").prev("p, div")[0].id, "ap", "Multiple filters" ); equal( jQuery("#foo").prev("p, div")[0].id, "ap", "Multiple filters" );
}); });
test("nextAll([String])", function() { test("nextAll([String])", function() {
...@@ -484,10 +484,10 @@ test("nextAll([String])", function() { ...@@ -484,10 +484,10 @@ test("nextAll([String])", function() {
var elems = jQuery("#form").children(); var elems = jQuery("#form").children();
same( jQuery("#label-for").nextAll().get(), elems.not(":first").get(), "Simple nextAll check" ); deepEqual( jQuery("#label-for").nextAll().get(), elems.not(":first").get(), "Simple nextAll check" );
same( jQuery("#label-for").nextAll("input").get(), elems.not(":first").filter("input").get(), "Filtered nextAll check" ); deepEqual( jQuery("#label-for").nextAll("input").get(), elems.not(":first").filter("input").get(), "Filtered nextAll check" );
same( jQuery("#label-for").nextAll("input,select").get(), elems.not(":first").filter("input,select").get(), "Multiple-filtered nextAll check" ); deepEqual( jQuery("#label-for").nextAll("input,select").get(), elems.not(":first").filter("input,select").get(), "Multiple-filtered nextAll check" );
same( jQuery("#label-for, #hidden1").nextAll("input,select").get(), elems.not(":first").filter("input,select").get(), "Multi-source, multiple-filtered nextAll check" ); deepEqual( jQuery("#label-for, #hidden1").nextAll("input,select").get(), elems.not(":first").filter("input,select").get(), "Multi-source, multiple-filtered nextAll check" );
}); });
test("prevAll([String])", function() { test("prevAll([String])", function() {
...@@ -495,10 +495,10 @@ test("prevAll([String])", function() { ...@@ -495,10 +495,10 @@ test("prevAll([String])", function() {
var elems = jQuery( jQuery("#form").children().slice(0, 12).get().reverse() ); var elems = jQuery( jQuery("#form").children().slice(0, 12).get().reverse() );
same( jQuery("#area1").prevAll().get(), elems.get(), "Simple prevAll check" ); deepEqual( jQuery("#area1").prevAll().get(), elems.get(), "Simple prevAll check" );
same( jQuery("#area1").prevAll("input").get(), elems.filter("input").get(), "Filtered prevAll check" ); deepEqual( jQuery("#area1").prevAll("input").get(), elems.filter("input").get(), "Filtered prevAll check" );
same( jQuery("#area1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multiple-filtered prevAll check" ); deepEqual( jQuery("#area1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multiple-filtered prevAll check" );
same( jQuery("#area1, #hidden1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multi-source, multiple-filtered prevAll check" ); deepEqual( jQuery("#area1, #hidden1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multi-source, multiple-filtered prevAll check" );
}); });
test("nextUntil([String])", function() { test("nextUntil([String])", function() {
...@@ -506,18 +506,18 @@ test("nextUntil([String])", function() { ...@@ -506,18 +506,18 @@ test("nextUntil([String])", function() {
var elems = jQuery("#form").children().slice( 2, 12 ); var elems = jQuery("#form").children().slice( 2, 12 );
same( jQuery("#text1").nextUntil().get(), jQuery("#text1").nextAll().get(), "nextUntil with no selector (nextAll)" ); deepEqual( jQuery("#text1").nextUntil().get(), jQuery("#text1").nextAll().get(), "nextUntil with no selector (nextAll)" );
same( jQuery("#text1").nextUntil(".foo").get(), jQuery("#text1").nextAll().get(), "nextUntil with invalid selector (nextAll)" ); deepEqual( jQuery("#text1").nextUntil(".foo").get(), jQuery("#text1").nextAll().get(), "nextUntil with invalid selector (nextAll)" );
same( jQuery("#text1").nextUntil("#area1").get(), elems.get(), "Simple nextUntil check" ); deepEqual( jQuery("#text1").nextUntil("#area1").get(), elems.get(), "Simple nextUntil check" );
equals( jQuery("#text1").nextUntil("#text2").length, 0, "Simple nextUntil check" ); equal( jQuery("#text1").nextUntil("#text2").length, 0, "Simple nextUntil check" );
same( jQuery("#text1").nextUntil("#area1, #radio1").get(), jQuery("#text1").next().get(), "Less simple nextUntil check" ); deepEqual( jQuery("#text1").nextUntil("#area1, #radio1").get(), jQuery("#text1").next().get(), "Less simple nextUntil check" );
same( jQuery("#text1").nextUntil("#area1", "input").get(), elems.not("button").get(), "Filtered nextUntil check" ); deepEqual( jQuery("#text1").nextUntil("#area1", "input").get(), elems.not("button").get(), "Filtered nextUntil check" );
same( jQuery("#text1").nextUntil("#area1", "button").get(), elems.not("input").get(), "Filtered nextUntil check" ); deepEqual( jQuery("#text1").nextUntil("#area1", "button").get(), elems.not("input").get(), "Filtered nextUntil check" );
same( jQuery("#text1").nextUntil("#area1", "button,input").get(), elems.get(), "Multiple-filtered nextUntil check" ); deepEqual( jQuery("#text1").nextUntil("#area1", "button,input").get(), elems.get(), "Multiple-filtered nextUntil check" );
equals( jQuery("#text1").nextUntil("#area1", "div").length, 0, "Filtered nextUntil check, no match" ); equal( jQuery("#text1").nextUntil("#area1", "div").length, 0, "Filtered nextUntil check, no match" );
same( jQuery("#text1, #hidden1").nextUntil("#area1", "button,input").get(), elems.get(), "Multi-source, multiple-filtered nextUntil check" ); deepEqual( jQuery("#text1, #hidden1").nextUntil("#area1", "button,input").get(), elems.get(), "Multi-source, multiple-filtered nextUntil check" );
same( jQuery("#text1").nextUntil("[class=foo]").get(), jQuery("#text1").nextAll().get(), "Non-element nodes must be skipped, since they have no attributes" ); deepEqual( jQuery("#text1").nextUntil("[class=foo]").get(), jQuery("#text1").nextAll().get(), "Non-element nodes must be skipped, since they have no attributes" );
}); });
test("prevUntil([String])", function() { test("prevUntil([String])", function() {
...@@ -525,54 +525,54 @@ test("prevUntil([String])", function() { ...@@ -525,54 +525,54 @@ test("prevUntil([String])", function() {
var elems = jQuery("#area1").prevAll(); var elems = jQuery("#area1").prevAll();
same( jQuery("#area1").prevUntil().get(), elems.get(), "prevUntil with no selector (prevAll)" ); deepEqual( jQuery("#area1").prevUntil().get(), elems.get(), "prevUntil with no selector (prevAll)" );
same( jQuery("#area1").prevUntil(".foo").get(), elems.get(), "prevUntil with invalid selector (prevAll)" ); deepEqual( jQuery("#area1").prevUntil(".foo").get(), elems.get(), "prevUntil with invalid selector (prevAll)" );
same( jQuery("#area1").prevUntil("label").get(), elems.not(":last").get(), "Simple prevUntil check" ); deepEqual( jQuery("#area1").prevUntil("label").get(), elems.not(":last").get(), "Simple prevUntil check" );
equals( jQuery("#area1").prevUntil("#button").length, 0, "Simple prevUntil check" ); equal( jQuery("#area1").prevUntil("#button").length, 0, "Simple prevUntil check" );
same( jQuery("#area1").prevUntil("label, #search").get(), jQuery("#area1").prev().get(), "Less simple prevUntil check" ); deepEqual( jQuery("#area1").prevUntil("label, #search").get(), jQuery("#area1").prev().get(), "Less simple prevUntil check" );
same( jQuery("#area1").prevUntil("label", "input").get(), elems.not(":last").not("button").get(), "Filtered prevUntil check" ); deepEqual( jQuery("#area1").prevUntil("label", "input").get(), elems.not(":last").not("button").get(), "Filtered prevUntil check" );
same( jQuery("#area1").prevUntil("label", "button").get(), elems.not(":last").not("input").get(), "Filtered prevUntil check" ); deepEqual( jQuery("#area1").prevUntil("label", "button").get(), elems.not(":last").not("input").get(), "Filtered prevUntil check" );
same( jQuery("#area1").prevUntil("label", "button,input").get(), elems.not(":last").get(), "Multiple-filtered prevUntil check" ); deepEqual( jQuery("#area1").prevUntil("label", "button,input").get(), elems.not(":last").get(), "Multiple-filtered prevUntil check" );
equals( jQuery("#area1").prevUntil("label", "div").length, 0, "Filtered prevUntil check, no match" ); equal( jQuery("#area1").prevUntil("label", "div").length, 0, "Filtered prevUntil check, no match" );
same( jQuery("#area1, #hidden1").prevUntil("label", "button,input").get(), elems.not(":last").get(), "Multi-source, multiple-filtered prevUntil check" ); deepEqual( jQuery("#area1, #hidden1").prevUntil("label", "button,input").get(), elems.not(":last").get(), "Multi-source, multiple-filtered prevUntil check" );
}); });
test("contents()", function() { test("contents()", function() {
expect(12); expect(12);
equals( jQuery("#ap").contents().length, 9, "Check element contents" ); equal( jQuery("#ap").contents().length, 9, "Check element contents" );
ok( jQuery("#iframe").contents()[0], "Check existance of IFrame document" ); ok( jQuery("#iframe").contents()[0], "Check existance of IFrame document" );
var ibody = jQuery("#loadediframe").contents()[0].body; var ibody = jQuery("#loadediframe").contents()[0].body;
ok( ibody, "Check existance of IFrame body" ); ok( ibody, "Check existance of IFrame body" );
equals( jQuery("span", ibody).text(), "span text", "Find span in IFrame and check its text" ); equal( jQuery("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
jQuery(ibody).append("<div>init text</div>"); jQuery(ibody).append("<div>init text</div>");
equals( jQuery("div", ibody).length, 2, "Check the original div and the new div are in IFrame" ); equal( jQuery("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
equals( jQuery("div:last", ibody).text(), "init text", "Add text to div in IFrame" ); equal( jQuery("div:last", ibody).text(), "init text", "Add text to div in IFrame" );
jQuery("div:last", ibody).text("div text"); jQuery("div:last", ibody).text("div text");
equals( jQuery("div:last", ibody).text(), "div text", "Add text to div in IFrame" ); equal( jQuery("div:last", ibody).text(), "div text", "Add text to div in IFrame" );
jQuery("div:last", ibody).remove(); jQuery("div:last", ibody).remove();
equals( jQuery("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" ); equal( jQuery("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
equals( jQuery("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" ); equal( jQuery("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
jQuery("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody); jQuery("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
jQuery("table", ibody).remove(); jQuery("table", ibody).remove();
equals( jQuery("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" ); equal( jQuery("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
var c = jQuery("#nonnodes").contents().contents(); var c = jQuery("#nonnodes").contents().contents();
equals( c.length, 1, "Check node,textnode,comment contents is just one" ); equal( c.length, 1, "Check node,textnode,comment contents is just one" );
equals( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" ); equal( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
}); });
test("add(String|Element|Array|undefined)", function() { test("add(String|Element|Array|undefined)", function() {
expect(16); expect(16);
same( jQuery("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" ); deepEqual( jQuery("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
same( jQuery("#sndp").add( jQuery("#en")[0] ).add( jQuery("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" ); deepEqual( jQuery("#sndp").add( jQuery("#en")[0] ).add( jQuery("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
// We no longer support .add(form.elements), unfortunately. // We no longer support .add(form.elements), unfortunately.
// There is no way, in browsers, to reliably determine the difference // There is no way, in browsers, to reliably determine the difference
...@@ -582,13 +582,13 @@ test("add(String|Element|Array|undefined)", function() { ...@@ -582,13 +582,13 @@ test("add(String|Element|Array|undefined)", function() {
// For the time being, we're discontinuing support for jQuery(form.elements) since it's ambiguous in IE // For the time being, we're discontinuing support for jQuery(form.elements) since it's ambiguous in IE
// use jQuery([]).add(form.elements) instead. // use jQuery([]).add(form.elements) instead.
//equals( jQuery([]).add(jQuery("#form")[0].elements).length, jQuery(jQuery("#form")[0].elements).length, "Array in constructor must equals array in add()" ); //equal( jQuery([]).add(jQuery("#form")[0].elements).length, jQuery(jQuery("#form")[0].elements).length, "Array in constructor must equals array in add()" );
var divs = jQuery("<div/>").add("#sndp"); var divs = jQuery("<div/>").add("#sndp");
ok( !divs[0].parentNode, "Make sure the first element is still the disconnected node." ); ok( !divs[0].parentNode, "Make sure the first element is still the disconnected node." );
divs = jQuery("<div>test</div>").add("#sndp"); divs = jQuery("<div>test</div>").add("#sndp");
equals( divs[0].parentNode.nodeType, 11, "Make sure the first element is still the disconnected node." ); equal( divs[0].parentNode.nodeType, 11, "Make sure the first element is still the disconnected node." );
divs = jQuery("#sndp").add("<div/>"); divs = jQuery("#sndp").add("<div/>");
ok( !divs[1].parentNode, "Make sure the first element is still the disconnected node." ); ok( !divs[1].parentNode, "Make sure the first element is still the disconnected node." );
...@@ -596,26 +596,26 @@ test("add(String|Element|Array|undefined)", function() { ...@@ -596,26 +596,26 @@ test("add(String|Element|Array|undefined)", function() {
var tmp = jQuery("<div/>"); var tmp = jQuery("<div/>");
var x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>").appendTo(tmp)).add(jQuery("<p id='x2'>xxx</p>").appendTo(tmp)); var x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>").appendTo(tmp)).add(jQuery("<p id='x2'>xxx</p>").appendTo(tmp));
equals( x[0].id, "x1", "Check on-the-fly element1" ); equal( x[0].id, "x1", "Check on-the-fly element1" );
equals( 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]); var x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>").appendTo(tmp)[0]).add(jQuery("<p id='x2'>xxx</p>").appendTo(tmp)[0]);
equals( x[0].id, "x1", "Check on-the-fly element1" ); equal( x[0].id, "x1", "Check on-the-fly element1" );
equals( 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>")); var x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>")).add(jQuery("<p id='x2'>xxx</p>"));
equals( x[0].id, "x1", "Check on-the-fly element1" ); equal( x[0].id, "x1", "Check on-the-fly element1" );
equals( 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>"); var x = jQuery([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
equals( x[0].id, "x1", "Check on-the-fly element1" ); equal( x[0].id, "x1", "Check on-the-fly element1" );
equals( x[1].id, "x2", "Check on-the-fly element2" ); equal( x[1].id, "x2", "Check on-the-fly element2" );
var notDefined; var notDefined;
equals( jQuery([]).add(notDefined).length, 0, "Check that undefined adds nothing" ); equal( jQuery([]).add(notDefined).length, 0, "Check that undefined adds nothing" );
equals( jQuery([]).add( document.getElementById("form") ).length, 1, "Add a form" ); equal( jQuery([]).add( document.getElementById("form") ).length, 1, "Add a form" );
equals( jQuery([]).add( document.getElementById("select1") ).length, 1, "Add a select" ); equal( jQuery([]).add( document.getElementById("select1") ).length, 1, "Add a select" );
}); });
test("add(String, Context)", function() { test("add(String, Context)", function() {
......
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