aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authortimmywil <tim.willison@thisismedium.com>2011-04-10 16:26:39 -0400
committertimmywil <tim.willison@thisismedium.com>2011-04-10 16:26:39 -0400
commitc10a76ec71b49575dad22b26c8675cfa8b41d862 (patch)
tree76233f0cc421bc952043063e1593d70be00fed45 /test
parentda89d8768cb53daac59f17a8acd8e6323a4d3be6 (diff)
parent7fb95ebe8f1b79220947d127a5d2b8bf56143622 (diff)
downloadjquery-c10a76ec71b49575dad22b26c8675cfa8b41d862.tar.gz
jquery-c10a76ec71b49575dad22b26c8675cfa8b41d862.zip
Merge branch 'master' into attrhooks.1.6v2
Diffstat (limited to 'test')
-rw-r--r--test/data/readywaitloader.js6
-rw-r--r--test/readywait.html18
-rw-r--r--test/unit/ajax.js2
-rw-r--r--test/unit/core.js38
-rw-r--r--test/unit/css.js32
-rw-r--r--test/unit/data.js19
-rw-r--r--test/unit/deferred.js378
-rw-r--r--test/unit/effects.js41
-rw-r--r--test/unit/event.js154
9 files changed, 514 insertions, 174 deletions
diff --git a/test/data/readywaitloader.js b/test/data/readywaitloader.js
index 483e07c4d..e07dac7a9 100644
--- a/test/data/readywaitloader.js
+++ b/test/data/readywaitloader.js
@@ -1,14 +1,14 @@
-// Simple script loader that uses jQuery.readyWait
+// Simple script loader that uses jQuery.readyWait via jQuery.holdReady()
//Hold on jQuery!
-jQuery.readyWait++;
+jQuery.holdReady(true);
var readyRegExp = /^(complete|loaded)$/;
function assetLoaded( evt ){
var node = evt.currentTarget || evt.srcElement;
if ( evt.type === "load" || readyRegExp.test(node.readyState) ) {
- jQuery.ready(true);
+ jQuery.holdReady(false);
}
}
diff --git a/test/readywait.html b/test/readywait.html
index 4f124767a..b4d8111eb 100644
--- a/test/readywait.html
+++ b/test/readywait.html
@@ -1,13 +1,13 @@
<!DOCTYPE html>
<html>
<!--
- Test for jQuery.readyWait. Needs to be a
+ Test for jQuery.holdReady. Needs to be a
standalone test since it deals with DOM
ready.
-->
<head>
<title>
- jQuery.readyWait Test
+ jQuery.holdReady Test
</title>
<style>
div { margin-top: 10px; }
@@ -52,15 +52,17 @@
</head>
<body>
<h1>
- jQuery.readyWait Test
+ jQuery.holdReady Test
</h1>
<p>
- This is a test page for jQuery.readyWait, that was
- added due to this ticket
- <a href="http://bugs.jquery.com/ticket/6781">#6781</a>.
+ This is a test page for jQuery.readyWait and jQuery.holdReady,
+ see
+ <a href="http://bugs.jquery.com/ticket/6781">#6781</a>
+ and
+ <a href="http://bugs.jquery.com/ticket/8803">#8803</a>.
</p>
<p>
- Test for jQuery.readyWait, which can be used
+ Test for jQuery.holdReady, which can be used
by plugins and other scripts to indicate something
important to the page is still loading and needs
to block the DOM ready callbacks that are registered
@@ -68,7 +70,7 @@
</p>
<p>
Script loaders are the most likely kind of script
- to use jQuery.readyWait, but it could be used by
+ to use jQuery.holdReady, but it could be used by
other things like a script that loads a CSS file
and wants to pause the DOM ready callbacks.
</p>
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index 7c572a32c..e9c7a00c5 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -1600,7 +1600,7 @@ test("jQuery.ajax() - malformed JSON", function() {
},
error: function(xhr, msg, detailedMsg) {
equals( "parsererror", msg, "A parse error occurred." );
- ok( /^Invalid JSON/.test(detailedMsg), "Detailed parsererror message provided" );
+ ok( /^(Invalid|SyntaxError|exception)/i.test(detailedMsg), "Detailed parsererror message provided" );
start();
}
});
diff --git a/test/unit/core.js b/test/unit/core.js
index 6ee8724de..79710025e 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -12,7 +12,7 @@ test("Basic requirements", function() {
});
test("jQuery()", function() {
- expect(24);
+ expect(25);
// Basic constructor's behavior
@@ -20,6 +20,7 @@ test("jQuery()", function() {
equals( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" );
equals( jQuery(null).length, 0, "jQuery(null) === jQuery([])" );
equals( jQuery("").length, 0, "jQuery('') === jQuery([])" );
+ equals( jQuery("#").length, 0, "jQuery('#') === jQuery([])" );
var obj = jQuery("div");
equals( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" );
@@ -171,6 +172,26 @@ test("selector state", function() {
);
});
+test( "globalEval", function() {
+
+ expect( 3 );
+
+ jQuery.globalEval( "var globalEvalTest = true;" );
+ ok( window.globalEvalTest, "Test variable declarations are global" );
+
+ window.globalEvalTest = false;
+
+ jQuery.globalEval( "globalEvalTest = true;" );
+ ok( window.globalEvalTest, "Test variable assignments are global" );
+
+ window.globalEvalTest = false;
+
+ jQuery.globalEval( "this.globalEvalTest = true;" );
+ ok( window.globalEvalTest, "Test context (this) is the window object" );
+
+ window.globalEvalTest = undefined;
+});
+
if ( !isLocal ) {
test("browser", function() {
stop();
@@ -468,7 +489,7 @@ test("isWindow", function() {
});
test("jQuery('html')", function() {
- expect(15);
+ expect(18);
QUnit.reset();
jQuery.foo = false;
@@ -500,6 +521,19 @@ test("jQuery('html')", function() {
ok( jQuery("<div></div>")[0], "Create a div with closing tag." );
ok( jQuery("<table></table>")[0], "Create a table with closing tag." );
+
+ // Test very large html string #7990
+ var i;
+ var li = '<li>very large html string</li>';
+ var html = ['<ul>'];
+ for ( i = 0; i < 50000; i += 1 ) {
+ html.push(li);
+ }
+ html.push('</ul>');
+ html = jQuery(html.join(''))[0];
+ equals( html.nodeName.toUpperCase(), 'UL');
+ equals( html.firstChild.nodeName.toUpperCase(), 'LI');
+ equals( html.childNodes.length, 50000 );
});
test("jQuery('html', context)", function() {
diff --git a/test/unit/css.js b/test/unit/css.js
index 8ae8fcb34..08f50ef25 100644
--- a/test/unit/css.js
+++ b/test/unit/css.js
@@ -105,6 +105,38 @@ test("css(String|Hash)", function() {
equals( child[0].style.fontSize, old, "Make sure font-size isn't changed on null." );
});
+test("css() explicit and relative values", function() {
+ expect(9);
+ var $elem = jQuery('#nothiddendiv');
+
+ $elem.css({ width: 1, height: 1 });
+ equals( $elem.width(), 1, "Initial css set or width/height works (hash)" );
+
+ $elem.css({ width: "+=9" });
+ equals( $elem.width(), 10, "'+=9' on width (hash)" );
+
+ $elem.css({ width: "-=9" });
+ equals( $elem.width(), 1, "'-=9' on width (hash)" );
+
+ $elem.css({ width: "+=9px" });
+ equals( $elem.width(), 10, "'+=9px' on width (hash)" );
+
+ $elem.css({ width: "-=9px" });
+ equals( $elem.width(), 1, "'-=9px' on width (hash)" );
+
+ $elem.css( "width", "+=9" );
+ equals( $elem.width(), 10, "'+=9' on width (params)" );
+
+ $elem.css( "width", "-=9" ) ;
+ equals( $elem.width(), 1, "'-=9' on width (params)" );
+
+ $elem.css( "width", "+=9px" );
+ equals( $elem.width(), 10, "'+=9px' on width (params)" );
+
+ $elem.css( "width", "-=9px" );
+ equals( $elem.width(), 1, "'-=9px' on width (params)" );
+});
+
test("css(String, Object)", function() {
expect(22);
diff --git a/test/unit/data.js b/test/unit/data.js
index 8fb7f35ad..94fa2a018 100644
--- a/test/unit/data.js
+++ b/test/unit/data.js
@@ -485,4 +485,21 @@ if (window.JSON && window.JSON.stringify) {
equals( JSON.stringify(obj), '{"foo":"bar"}', "Expando is hidden from JSON.stringify" );
});
-} \ No newline at end of file
+}
+
+test("jQuery.data should follow html5 specification regarding camel casing", function() {
+ expect(6);
+
+ var div = jQuery("<div id='myObject' data-foo='a' data-foo-bar='b' data-foo-bar-baz='c'></div>")
+ .prependTo("body");
+
+ equals(div.data().foo, "a", "Verify single word data-* key");
+ equals(div.data().fooBar, "b", "Verify multiple word data-* key");
+ equals(div.data().fooBarBaz, "c", "Verify multiple word data-* key");
+
+ equals(div.data("foo"), "a", "Verify single word data-* key");
+ equals(div.data("fooBar"), "b", "Verify multiple word data-* key");
+ equals(div.data("fooBarBaz"), "c", "Verify multiple word data-* key");
+
+ div.remove();
+}); \ No newline at end of file
diff --git a/test/unit/deferred.js b/test/unit/deferred.js
index 6ba4767a6..c71fbdbe7 100644
--- a/test/unit/deferred.js
+++ b/test/unit/deferred.js
@@ -1,153 +1,273 @@
module("deferred", { teardown: moduleTeardown });
-test("jQuery._Deferred()", function() {
+jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
- expect( 11 );
+ function createDeferred() {
+ return withNew ? new jQuery._Deferred() : jQuery._Deferred();
+ }
- var deferred,
- object,
- test;
+ test("jQuery._Deferred" + withNew, function() {
- deferred = jQuery._Deferred();
+ expect( 11 );
- test = false;
+ var deferred,
+ object,
+ test;
- deferred.done( function( value ) {
- equals( value , "value" , "Test pre-resolve callback" );
- test = true;
- } );
+ deferred = createDeferred();
- deferred.resolve( "value" );
-
- ok( test , "Test pre-resolve callbacks called right away" );
+ test = false;
- test = false;
+ deferred.done( function( value ) {
+ equals( value , "value" , "Test pre-resolve callback" );
+ test = true;
+ } );
- deferred.done( function( value ) {
- equals( value , "value" , "Test post-resolve callback" );
- test = true;
- } );
+ deferred.resolve( "value" );
- ok( test , "Test post-resolve callbacks called right away" );
+ ok( test , "Test pre-resolve callbacks called right away" );
- deferred.cancel();
+ test = false;
- test = true;
+ deferred.done( function( value ) {
+ equals( value , "value" , "Test post-resolve callback" );
+ test = true;
+ } );
- deferred.done( function() {
- ok( false , "Cancel was ignored" );
- test = false;
- } );
+ ok( test , "Test post-resolve callbacks called right away" );
- ok( test , "Test cancel" );
+ deferred.cancel();
- deferred = jQuery._Deferred().resolve();
+ test = true;
- try {
deferred.done( function() {
- throw "Error";
- } , function() {
- ok( true , "Test deferred do not cancel on exception" );
+ ok( false , "Cancel was ignored" );
+ test = false;
} );
- } catch( e ) {
- strictEqual( e , "Error" , "Test deferred propagates exceptions");
- deferred.done();
- }
- test = "";
- deferred = jQuery._Deferred().done( function() {
+ ok( test , "Test cancel" );
- test += "A";
+ deferred = createDeferred().resolve();
- }, function() {
+ try {
+ deferred.done( function() {
+ throw "Error";
+ } , function() {
+ ok( true , "Test deferred do not cancel on exception" );
+ } );
+ } catch( e ) {
+ strictEqual( e , "Error" , "Test deferred propagates exceptions");
+ deferred.done();
+ }
- test += "B";
+ test = "";
+ deferred = createDeferred().done( function() {
- } ).resolve();
+ test += "A";
- strictEqual( test , "AB" , "Test multiple done parameters" );
+ }, function() {
+
+ test += "B";
- test = "";
+ } ).resolve();
- deferred.done( function() {
+ strictEqual( test , "AB" , "Test multiple done parameters" );
+
+ test = "";
deferred.done( function() {
- test += "C";
+ deferred.done( function() {
+
+ test += "C";
+ } );
+
+ test += "A";
+
+ }, function() {
+
+ test += "B";
} );
- test += "A";
+ strictEqual( test , "ABC" , "Test done callbacks order" );
- }, function() {
+ deferred = createDeferred();
- test += "B";
- } );
+ deferred.resolveWith( jQuery , [ document ] ).done( function( doc ) {
+ ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" );
+ });
+
+ // #8421
+ deferred = createDeferred();
+ deferred.resolveWith().done(function() {
+ ok( true, "Test resolveWith can be called with no argument" );
+ });
+ });
+} );
+
+jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
+
+ function createDeferred( fn ) {
+ return withNew ? new jQuery.Deferred( fn ) : jQuery.Deferred( fn );
+ }
+
+ test("jQuery.Deferred" + withNew, function() {
+
+ expect( 8 );
+
+ createDeferred().resolve().then( function() {
+ ok( true , "Success on resolve" );
+ ok( this.isResolved(), "Deferred is resolved" );
+ }, function() {
+ ok( false , "Error on resolve" );
+ }).always( function() {
+ ok( true , "Always callback on resolve" );
+ });
+
+ createDeferred().reject().then( function() {
+ ok( false , "Success on reject" );
+ }, function() {
+ ok( true , "Error on reject" );
+ ok( this.isRejected(), "Deferred is rejected" );
+ }).always( function() {
+ ok( true , "Always callback on reject" );
+ });
+
+ createDeferred( function( defer ) {
+ ok( this === defer , "Defer passed as this & first argument" );
+ this.resolve( "done" );
+ }).then( function( value ) {
+ strictEqual( value , "done" , "Passed function executed" );
+ });
+ });
+} );
- strictEqual( test , "ABC" , "Test done callbacks order" );
+test( "jQuery.Deferred.pipe - filtering (done)", function() {
- deferred = jQuery._Deferred();
+ expect(3);
- deferred.resolveWith( jQuery , [ document ] ).done( function( doc ) {
- ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" );
+ var defer = jQuery.Deferred(),
+ piped = defer.pipe(function( a, b ) {
+ return a * b;
+ }),
+ value1,
+ value2,
+ value3;
+
+ piped.done(function( result ) {
+ value3 = result;
+ });
+
+ defer.done(function( a, b ) {
+ value1 = a;
+ value2 = b;
});
- // #8421
- deferred = jQuery._Deferred();
- deferred.resolveWith().done(function() {
- ok( true, "Test resolveWith can be called with no argument" );
+ defer.resolve( 2, 3 );
+
+ strictEqual( value1, 2, "first resolve value ok" );
+ strictEqual( value2, 3, "second resolve value ok" );
+ strictEqual( value3, 6, "result of filter ok" );
+
+ jQuery.Deferred().reject().pipe(function() {
+ ok( false, "pipe should not be called on reject" );
});
});
-test("jQuery.Deferred()", function() {
+test( "jQuery.Deferred.pipe - filtering (fail)", function() {
+
+ expect(3);
- expect( 10 );
+ var defer = jQuery.Deferred(),
+ piped = defer.pipe( null, function( a, b ) {
+ return a * b;
+ } ),
+ value1,
+ value2,
+ value3;
- jQuery.Deferred( function( defer ) {
- strictEqual( this , defer , "Defer passed as this & first argument" );
- this.resolve( "done" );
- }).then( function( value ) {
- strictEqual( value , "done" , "Passed function executed" );
+ piped.fail(function( result ) {
+ value3 = result;
});
- jQuery.Deferred().resolve().then( function() {
- ok( true , "Success on resolve" );
- }, function() {
- ok( false , "Error on resolve" );
+ defer.fail(function( a, b ) {
+ value1 = a;
+ value2 = b;
});
- jQuery.Deferred().reject().then( function() {
- ok( false , "Success on reject" );
- }, function() {
- ok( true , "Error on reject" );
+ defer.reject( 2, 3 );
+
+ strictEqual( value1, 2, "first reject value ok" );
+ strictEqual( value2, 3, "second reject value ok" );
+ strictEqual( value3, 6, "result of filter ok" );
+
+ jQuery.Deferred().resolve().pipe( null, function() {
+ ok( false, "pipe should not be called on resolve" );
+ } );
+});
+
+test( "jQuery.Deferred.pipe - deferred (done)", function() {
+
+ expect(3);
+
+ var defer = jQuery.Deferred(),
+ piped = defer.pipe(function( a, b ) {
+ return jQuery.Deferred(function( defer ) {
+ defer.reject( a * b );
+ });
+ }),
+ value1,
+ value2,
+ value3;
+
+ piped.fail(function( result ) {
+ value3 = result;
});
- ( new jQuery.Deferred( function( defer ) {
- strictEqual( this , defer , "Defer passed as this & first argument (new)" );
- this.resolve( "done" );
- }) ).then( function( value ) {
- strictEqual( value , "done" , "Passed function executed (new)" );
+ defer.done(function( a, b ) {
+ value1 = a;
+ value2 = b;
});
- ( new jQuery.Deferred() ).resolve().then( function() {
- ok( true , "Success on resolve (new)" );
- }, function() {
- ok( false , "Error on resolve (new)" );
+ defer.resolve( 2, 3 );
+
+ strictEqual( value1, 2, "first resolve value ok" );
+ strictEqual( value2, 3, "second resolve value ok" );
+ strictEqual( value3, 6, "result of filter ok" );
+});
+
+test( "jQuery.Deferred.pipe - deferred (fail)", function() {
+
+ expect(3);
+
+ var defer = jQuery.Deferred(),
+ piped = defer.pipe( null, function( a, b ) {
+ return jQuery.Deferred(function( defer ) {
+ defer.resolve( a * b );
+ });
+ } ),
+ value1,
+ value2,
+ value3;
+
+ piped.done(function( result ) {
+ value3 = result;
});
- ( new jQuery.Deferred() ).reject().then( function() {
- ok( false , "Success on reject (new)" );
- }, function() {
- ok( true , "Error on reject (new)" );
+ defer.fail(function( a, b ) {
+ value1 = a;
+ value2 = b;
});
- var tmp = jQuery.Deferred();
+ defer.reject( 2, 3 );
- strictEqual( tmp.promise() , tmp.promise() , "Test deferred always return same promise" );
- strictEqual( tmp.promise() , tmp.promise().promise() , "Test deferred's promise always return same promise as deferred" );
+ strictEqual( value1, 2, "first reject value ok" );
+ strictEqual( value2, 3, "second reject value ok" );
+ strictEqual( value3, 6, "result of filter ok" );
});
-test("jQuery.when()", function() {
+test( "jQuery.when" , function() {
expect( 23 );
@@ -166,57 +286,63 @@ test("jQuery.when()", function() {
} , function( message , value ) {
- ok( jQuery.isFunction( jQuery.when( value ).then( function( resolveValue ) {
+ ok( jQuery.isFunction( jQuery.when( value ).done(function( resolveValue ) {
strictEqual( resolveValue , value , "Test the promise was resolved with " + message );
- } ).promise ) , "Test " + message + " triggers the creation of a new Promise" );
+ }).promise ) , "Test " + message + " triggers the creation of a new Promise" );
} );
- ok( jQuery.isFunction( jQuery.when().then( function( resolveValue ) {
+ ok( jQuery.isFunction( jQuery.when().done(function( resolveValue ) {
strictEqual( resolveValue , undefined , "Test the promise was resolved with no parameter" );
- } ).promise ) , "Test calling when with no parameter triggers the creation of a new Promise" );
+ }).promise ) , "Test calling when with no parameter triggers the creation of a new Promise" );
var cache, i;
for( i = 1 ; i < 4 ; i++ ) {
jQuery.when( cache || jQuery.Deferred( function() {
this.resolve( i );
- }) ).then( function( value ) {
+ }) ).done(function( value ) {
strictEqual( value , 1 , "Function executed" + ( i > 1 ? " only once" : "" ) );
cache = value;
- }, function() {
- ok( false , "Fail called" );
});
}
});
-test("jQuery.when() - joined", function() {
-
- expect(8);
-
- jQuery.when( 1, 2, 3 ).done( function( a, b, c ) {
- strictEqual( a , 1 , "Test first param is first resolved value - non-observables" );
- strictEqual( b , 2 , "Test second param is second resolved value - non-observables" );
- strictEqual( c , 3 , "Test third param is third resolved value - non-observables" );
- }).fail( function() {
- ok( false , "Test the created deferred was resolved - non-observables");
- });
-
- var successDeferred = jQuery.Deferred().resolve( 1 , 2 , 3 ),
- errorDeferred = jQuery.Deferred().reject( "error" , "errorParam" );
-
- jQuery.when( 1 , successDeferred , 3 ).done( function( a, b, c ) {
- strictEqual( a , 1 , "Test first param is first resolved value - resolved observable" );
- same( b , [ 1 , 2 , 3 ] , "Test second param is second resolved value - resolved observable" );
- strictEqual( c , 3 , "Test third param is third resolved value - resolved observable" );
- }).fail( function() {
- ok( false , "Test the created deferred was resolved - resolved observable");
- });
-
- jQuery.when( 1 , errorDeferred , 3 ).done( function() {
- ok( false , "Test the created deferred was rejected - rejected observable");
- }).fail( function( error , errorParam ) {
- strictEqual( error , "error" , "Test first param is first rejected value - rejected observable" );
- strictEqual( errorParam , "errorParam" , "Test second param is second rejected value - rejected observable" );
- });
+test("jQuery.when - joined", function() {
+
+ expect(25);
+
+ var deferreds = {
+ value: 1,
+ success: jQuery.Deferred().resolve( 1 ),
+ error: jQuery.Deferred().reject( 0 ),
+ futureSuccess: jQuery.Deferred(),
+ futureError: jQuery.Deferred()
+ },
+ willSucceed = {
+ value: true,
+ success: true,
+ error: false,
+ futureSuccess: true,
+ futureError: false
+ };
+
+ jQuery.each( deferreds, function( id1, defer1 ) {
+ jQuery.each( deferreds, function( id2, defer2 ) {
+ var shouldResolve = willSucceed[ id1 ] && willSucceed[ id2 ],
+ expected = shouldResolve ? [ 1, 1 ] : [ 0, undefined ],
+ code = id1 + "/" + id2;
+ jQuery.when( defer1, defer2 ).done(function( a, b ) {
+ if ( shouldResolve ) {
+ same( [ a, b ], expected, code + " => resolve" );
+ }
+ }).fail(function( a, b ) {
+ if ( !shouldResolve ) {
+ same( [ a, b ], expected, code + " => resolve" );
+ }
+ });
+ } );
+ } );
+ deferreds.futureSuccess.resolve( 1 );
+ deferreds.futureError.reject( 0 );
});
diff --git a/test/unit/effects.js b/test/unit/effects.js
index c0a812f45..4f6785111 100644
--- a/test/unit/effects.js
+++ b/test/unit/effects.js
@@ -717,59 +717,64 @@ jQuery.each( {
var anim = { width: t_w, height: t_h, opacity: t_o };
- elem.animate(anim, 50, function(){
+ elem.animate(anim, 50);
+
+ jQuery.when( elem ).done(function( elem ){
+
+ elem = elem[ 0 ];
+
if ( t_w == "show" )
- equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
+ equals( elem.style.display, "block", "Showing, display should block: " + elem.style.display);
if ( t_w == "hide"||t_w == "show" )
- ok(f_w === "" ? this.style.width === f_w : this.style.width.indexOf(f_w) === 0, "Width must be reset to " + f_w + ": " + this.style.width);
+ ok(f_w === "" ? elem.style.width === f_w : elem.style.width.indexOf(f_w) === 0, "Width must be reset to " + f_w + ": " + elem.style.width);
if ( t_h == "hide"||t_h == "show" )
- ok(f_h === "" ? this.style.height === f_h : this.style.height.indexOf(f_h) === 0, "Height must be reset to " + f_h + ": " + this.style.height);
+ ok(f_h === "" ? elem.style.height === f_h : elem.style.height.indexOf(f_h) === 0, "Height must be reset to " + f_h + ": " + elem.style.height);
- var cur_o = jQuery.style(this, "opacity");
+ var cur_o = jQuery.style(elem, "opacity");
if ( t_o == "hide" || t_o == "show" )
equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
if ( t_w == "hide" )
- equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
+ equals(elem.style.display, "none", "Hiding, display should be none: " + elem.style.display);
if ( t_o.constructor == Number ) {
equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
- ok(jQuery.css(this, "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 ) {
- equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
+ equals(elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width);
- var cur_w = jQuery.css(this,"width");
+ var cur_w = jQuery.css(elem,"width");
- ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
+ ok(elem.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
}
if ( t_h.constructor == Number ) {
- equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
+ equals(elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height);
- var cur_h = jQuery.css(this,"height");
+ var cur_h = jQuery.css(elem,"height");
- ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
+ ok(elem.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
}
if ( t_h == "show" ) {
- var old_h = jQuery.css(this, "height");
- jQuery(this).append("<br/>Some more text<br/>and some more...");
+ var old_h = jQuery.css(elem, "height");
+ jQuery(elem).append("<br/>Some more text<br/>and some more...");
if ( /Auto/.test( fn ) ) {
- notEqual(jQuery.css(this, "height"), old_h, "Make sure height is auto.");
+ notEqual(jQuery.css(elem, "height"), old_h, "Make sure height is auto.");
} else {
- equals(jQuery.css(this, "height"), old_h, "Make sure height is not auto.");
+ equals(jQuery.css(elem, "height"), old_h, "Make sure height is not auto.");
}
}
// manually remove generated element
- jQuery(this).remove();
+ jQuery(elem).remove();
start();
});
diff --git a/test/unit/event.js b/test/unit/event.js
index 2a6d8a669..50bf4e174 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -550,6 +550,47 @@ test("bind(name, false), unbind(name, false)", function() {
jQuery("#main").unbind("click");
});
+test("live(name, false), die(name, false)", function() {
+ expect(3);
+
+ var main = 0;
+ jQuery("#main").live("click", function(e){ main++; });
+ jQuery("#ap").trigger("click");
+ equals( main, 1, "Verify that the trigger happened correctly." );
+
+ main = 0;
+ jQuery("#ap").live("click", false);
+ jQuery("#ap").trigger("click");
+ equals( main, 0, "Verify that no bubble happened." );
+
+ main = 0;
+ jQuery("#ap").die("click", false);
+ jQuery("#ap").trigger("click");
+ equals( main, 1, "Verify that the trigger happened correctly." );
+ jQuery("#main").die("click");
+});
+
+test("delegate(selector, name, false), undelegate(selector, name, false)", function() {
+ expect(3);
+
+ var main = 0;
+
+ jQuery("#main").delegate("#ap", "click", function(e){ main++; });
+ jQuery("#ap").trigger("click");
+ equals( main, 1, "Verify that the trigger happened correctly." );
+
+ main = 0;
+ jQuery("#ap").delegate("#groups", "click", false);
+ jQuery("#groups").trigger("click");
+ equals( main, 0, "Verify that no bubble happened." );
+
+ main = 0;
+ jQuery("#ap").undelegate("#groups", "click", false);
+ jQuery("#groups").trigger("click");
+ equals( main, 1, "Verify that the trigger happened correctly." );
+ jQuery("#main").undelegate("#ap", "click");
+});
+
test("bind()/trigger()/unbind() on plain object", function() {
expect( 7 );
@@ -685,7 +726,7 @@ test("hover()", function() {
test("mouseover triggers mouseenter", function() {
expect(1);
-
+
var count = 0,
elem = jQuery("<a />");
elem.mouseenter(function () {
@@ -693,7 +734,7 @@ test("mouseover triggers mouseenter", function() {
});
elem.trigger('mouseover');
equals(count, 1, "make sure mouseover triggers a mouseenter" );
-
+
elem.remove();
});
@@ -738,10 +779,11 @@ test("trigger() shortcuts", function() {
});
test("trigger() bubbling", function() {
- expect(14);
+ expect(17);
- var doc = 0, html = 0, body = 0, main = 0, ap = 0;
+ var win = 0, doc = 0, html = 0, body = 0, main = 0, ap = 0;
+ jQuery(window).bind("click", function(e){ win++; });
jQuery(document).bind("click", function(e){ if ( e.target !== document) { doc++; } });
jQuery("html").bind("click", function(e){ html++; });
jQuery("body").bind("click", function(e){ body++; });
@@ -749,15 +791,18 @@ test("trigger() bubbling", function() {
jQuery("#ap").bind("click", function(){ ap++; return false; });
jQuery("html").trigger("click");
+ equals( win, 1, "HTML bubble" );
equals( doc, 1, "HTML bubble" );
equals( html, 1, "HTML bubble" );
jQuery("body").trigger("click");
+ equals( win, 2, "Body bubble" );
equals( doc, 2, "Body bubble" );
equals( html, 2, "Body bubble" );
equals( body, 1, "Body bubble" );
jQuery("#main").trigger("click");
+ equals( win, 3, "Main bubble" );
equals( doc, 3, "Main bubble" );
equals( html, 3, "Main bubble" );
equals( body, 2, "Main bubble" );
@@ -1982,8 +2027,8 @@ test("window resize", function() {
test("focusin bubbles", function() {
expect(5);
-
- var input = jQuery( '<input type="text" />' ).prependTo( "body" ),
+
+ var input = jQuery( '<input type="text" />' ).prependTo( "body" ),
order = 0;
jQuery( "body" ).bind( "focusin.focusinBubblesTest", function(){
@@ -1996,12 +2041,12 @@ test("focusin bubbles", function() {
// DOM focus method
input[0].focus();
-
+
// To make the next focus test work, we need to take focus off the input.
// This will fire another focusin event, so set order to reflect that.
order = 1;
jQuery("#text1")[0].focus();
-
+
// jQuery trigger, which calls DOM focus
order = 0;
input.trigger( "focus" );
@@ -2010,15 +2055,94 @@ test("focusin bubbles", function() {
jQuery( "body" ).unbind( "focusin.focusinBubblesTest" );
});
-/*
-test("jQuery(function($) {})", function() {
- stop();
- jQuery(function($) {
- equals(jQuery, $, "ready doesn't provide an event object, instead it provides a reference to the jQuery function, see http://docs.jquery.com/Events/ready#fn");
- start();
- });
+test("custom events with colons (#3533, #8272)", function() {
+ expect(1);
+
+ var tab = jQuery("<table><tr><td>trigger</td></tr></table>").appendTo("body");
+ try {
+ tab.trigger("back:forth");
+ ok( true, "colon events don't throw" );
+ } catch ( e ) {
+ ok( false, "colon events die" );
+ };
+ tab.remove();
+
});
+(function(){
+ // This code must be run before DOM ready!
+ var notYetReady, noEarlyExecution,
+ order = [],
+ args = {};
+
+ notYetReady = !jQuery.isReady;
+
+ test("jQuery.isReady", function() {
+ expect(2);
+
+ equals(notYetReady, true, "jQuery.isReady should not be true before DOM ready");
+ equals(jQuery.isReady, true, "jQuery.isReady should be true once DOM is ready");
+ });
+
+ // Create an event handler.
+ function makeHandler( testId ) {
+ // When returned function is executed, push testId onto `order` array
+ // to ensure execution order. Also, store event handler arg to ensure
+ // the correct arg is being passed into the event handler.
+ return function( arg ) {
+ order.push(testId);
+ args[testId] = arg;
+ };
+ }
+
+ // Bind to the ready event in every possible way.
+ jQuery(makeHandler("a"));
+ jQuery(document).ready(makeHandler("b"));
+ jQuery(document).bind("ready.readytest", makeHandler("c"));
+
+ // Do it twice, just to be sure.
+ jQuery(makeHandler("d"));
+ jQuery(document).ready(makeHandler("e"));
+ jQuery(document).bind("ready.readytest", makeHandler("f"));
+
+ noEarlyExecution = order.length == 0;
+
+ // This assumes that QUnit tests are run on DOM ready!
+ test("jQuery ready", function() {
+ expect(10);
+
+ ok(noEarlyExecution, "Handlers bound to DOM ready should not execute before DOM ready");
+
+ // 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");
+
+ // Ensure handler argument is correct.
+ equals(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");
+ ok(args.c instanceof jQuery.Event, "Argument passed to fn in jQuery(document).bind( 'ready', fn ) should be an event object");
+
+ order = [];
+
+ // Now that the ready event has fired, again bind to the ready event
+ // in every possible way. These event handlers should execute immediately.
+ jQuery(makeHandler("g"));
+ equals(order.pop(), "g", "Event handler should execute immediately");
+ equals(args.g, jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery");
+
+ jQuery(document).ready(makeHandler("h"));
+ equals(order.pop(), "h", "Event handler should execute immediately");
+ equals(args.h, jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery");
+
+ jQuery(document).bind("ready.readytest", makeHandler("never"));
+ equals(order.length, 0, "Event handler should never execute since DOM ready has already passed");
+
+ // Cleanup.
+ jQuery(document).unbind("ready.readytest");
+ });
+
+})();
+
+/*
test("event properties", function() {
stop();
jQuery("#simon1").click(function(event) {