2019-02-18 18:02:38 +00:00
|
|
|
QUnit.module( "deprecated", { afterEach: moduleTeardown } );
|
2013-04-08 22:18:45 +00:00
|
|
|
|
2015-10-01 20:03:10 +00:00
|
|
|
|
2020-01-07 22:59:08 +00:00
|
|
|
QUnit[ jQuery.fn.bind ? "test" : "skip" ]( "bind/unbind", function( assert ) {
|
2015-10-01 20:03:10 +00:00
|
|
|
assert.expect( 4 );
|
|
|
|
|
|
|
|
var markup = jQuery(
|
|
|
|
"<div><p><span><b>b</b></span></p></div>"
|
|
|
|
);
|
|
|
|
|
|
|
|
markup
|
|
|
|
.find( "b" )
|
|
|
|
.bind( "click", { bindData: 19 }, function( e, trig ) {
|
|
|
|
assert.equal( e.type, "click", "correct event type" );
|
|
|
|
assert.equal( e.data.bindData, 19, "correct trigger data" );
|
|
|
|
assert.equal( trig, 42, "correct bind data" );
|
2016-05-10 09:12:28 +00:00
|
|
|
assert.equal( e.target.nodeName.toLowerCase(), "b", "correct element" );
|
2015-10-01 20:03:10 +00:00
|
|
|
} )
|
|
|
|
.trigger( "click", [ 42 ] )
|
|
|
|
.unbind( "click" )
|
|
|
|
.trigger( "click" )
|
|
|
|
.remove();
|
|
|
|
} );
|
|
|
|
|
2020-01-07 22:59:08 +00:00
|
|
|
QUnit[ jQuery.fn.delegate ? "test" : "skip" ]( "delegate/undelegate", function( assert ) {
|
2015-10-01 20:03:10 +00:00
|
|
|
assert.expect( 2 );
|
|
|
|
|
|
|
|
var markup = jQuery(
|
|
|
|
"<div><p><span><b>b</b></span></p></div>"
|
|
|
|
);
|
|
|
|
|
|
|
|
markup
|
|
|
|
.delegate( "b", "click", function( e ) {
|
|
|
|
assert.equal( e.type, "click", "correct event type" );
|
2016-05-10 09:12:28 +00:00
|
|
|
assert.equal( e.target.nodeName.toLowerCase(), "b", "correct element" );
|
2015-10-01 20:03:10 +00:00
|
|
|
} )
|
|
|
|
.find( "b" )
|
|
|
|
.trigger( "click" )
|
|
|
|
.end()
|
|
|
|
.undelegate( "b", "click" )
|
|
|
|
.remove();
|
2016-02-24 22:47:19 +00:00
|
|
|
} );
|
|
|
|
|
2019-05-13 19:39:56 +00:00
|
|
|
QUnit[ jQuery.fn.hover ? "test" : "skip" ]( "hover() mouseenter mouseleave", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2017-12-29 21:58:45 +00:00
|
|
|
|
2019-05-13 19:39:56 +00:00
|
|
|
var times = 0,
|
|
|
|
handler1 = function() { ++times; },
|
|
|
|
handler2 = function() { ++times; };
|
2017-12-29 21:58:45 +00:00
|
|
|
|
2019-05-13 19:39:56 +00:00
|
|
|
jQuery( "#firstp" )
|
|
|
|
.hover( handler1, handler2 )
|
|
|
|
.mouseenter().mouseleave()
|
|
|
|
.off( "mouseenter", handler1 )
|
|
|
|
.off( "mouseleave", handler2 )
|
|
|
|
.hover( handler1 )
|
|
|
|
.mouseenter().mouseleave()
|
|
|
|
.off( "mouseenter mouseleave", handler1 )
|
|
|
|
.mouseenter().mouseleave();
|
2017-12-29 21:58:45 +00:00
|
|
|
|
2019-05-13 19:39:56 +00:00
|
|
|
assert.equal( times, 4, "hover handlers fired" );
|
|
|
|
} );
|
2017-12-29 21:58:45 +00:00
|
|
|
|
|
|
|
QUnit[ jQuery.fn.click ? "test" : "skip" ]( "trigger() shortcuts", function( assert ) {
|
|
|
|
assert.expect( 5 );
|
|
|
|
|
|
|
|
var counter, clickCounter,
|
|
|
|
elem = jQuery( "<li><a href='#'>Change location</a></li>" ).prependTo( "#firstUL" );
|
|
|
|
elem.find( "a" ).on( "click", function() {
|
|
|
|
var close = jQuery( "spanx", this ); // same with jQuery(this).find("span");
|
|
|
|
assert.equal( close.length, 0, "Context element does not exist, length must be zero" );
|
|
|
|
assert.ok( !close[ 0 ], "Context element does not exist, direct access to element must return undefined" );
|
|
|
|
return false;
|
|
|
|
} ).click();
|
|
|
|
|
|
|
|
// manually clean up detached elements
|
|
|
|
elem.remove();
|
|
|
|
|
|
|
|
jQuery( "#check1" ).click( function() {
|
|
|
|
assert.ok( true, "click event handler for checkbox gets fired twice, see #815" );
|
|
|
|
} ).click();
|
|
|
|
|
|
|
|
counter = 0;
|
|
|
|
jQuery( "#firstp" )[ 0 ].onclick = function() {
|
|
|
|
counter++;
|
|
|
|
};
|
|
|
|
jQuery( "#firstp" ).click();
|
|
|
|
assert.equal( counter, 1, "Check that click, triggers onclick event handler also" );
|
|
|
|
|
|
|
|
clickCounter = 0;
|
|
|
|
jQuery( "#simon1" )[ 0 ].onclick = function() {
|
|
|
|
clickCounter++;
|
|
|
|
};
|
|
|
|
jQuery( "#simon1" ).click();
|
|
|
|
assert.equal( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" );
|
|
|
|
} );
|
|
|
|
|
2020-01-07 22:59:08 +00:00
|
|
|
if ( jQuery.ajax && jQuery.fn.ajaxSend ) {
|
|
|
|
ajaxTest( "jQuery.ajax() - events with context", 12, function( assert ) {
|
|
|
|
var context = document.createElement( "div" );
|
|
|
|
|
|
|
|
function event( e ) {
|
|
|
|
assert.equal( this, context, e.type );
|
|
|
|
}
|
|
|
|
|
|
|
|
function callback( msg ) {
|
|
|
|
return function() {
|
|
|
|
assert.equal( this, context, "context is preserved on callback " + msg );
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
setup: function() {
|
|
|
|
jQuery( context ).appendTo( "#foo" )
|
|
|
|
.ajaxSend( event )
|
|
|
|
.ajaxComplete( event )
|
|
|
|
.ajaxError( event )
|
|
|
|
.ajaxSuccess( event );
|
|
|
|
},
|
|
|
|
requests: [ {
|
|
|
|
url: url( "name.html" ),
|
|
|
|
context: context,
|
|
|
|
beforeSend: callback( "beforeSend" ),
|
|
|
|
success: callback( "success" ),
|
|
|
|
complete: callback( "complete" )
|
|
|
|
}, {
|
|
|
|
url: url( "404.txt" ),
|
|
|
|
context: context,
|
|
|
|
beforeSend: callback( "beforeSend" ),
|
|
|
|
error: callback( "error" ),
|
|
|
|
complete: callback( "complete" )
|
|
|
|
} ]
|
|
|
|
};
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2017-12-29 21:58:45 +00:00
|
|
|
QUnit[ jQuery.fn.click ? "test" : "skip" ]( "Event aliases", function( assert ) {
|
|
|
|
|
|
|
|
// Explicitly skipping focus/blur events due to their flakiness
|
2020-03-16 20:49:29 +00:00
|
|
|
var $elem = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ),
|
2017-12-29 21:58:45 +00:00
|
|
|
aliases = ( "resize scroll click dblclick mousedown mouseup " +
|
|
|
|
"mousemove mouseover mouseout mouseenter mouseleave change " +
|
|
|
|
"select submit keydown keypress keyup contextmenu" ).split( " " );
|
|
|
|
assert.expect( aliases.length );
|
|
|
|
|
|
|
|
jQuery.each( aliases, function( i, name ) {
|
|
|
|
|
|
|
|
// e.g. $(elem).click(...).click();
|
|
|
|
$elem[ name ]( function( event ) {
|
|
|
|
assert.equal( event.type, name, "triggered " + name );
|
|
|
|
} )[ name ]().off( name );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2020-01-07 22:59:08 +00:00
|
|
|
QUnit[ jQuery.proxy ? "test" : "skip" ]( "jQuery.proxy", function( assert ) {
|
2017-12-11 17:58:35 +00:00
|
|
|
assert.expect( 9 );
|
|
|
|
|
|
|
|
var test2, test3, test4, fn, cb,
|
|
|
|
test = function() {
|
|
|
|
assert.equal( this, thisObject, "Make sure that scope is set properly." );
|
|
|
|
},
|
|
|
|
thisObject = { foo: "bar", method: test };
|
|
|
|
|
|
|
|
// Make sure normal works
|
|
|
|
test.call( thisObject );
|
|
|
|
|
|
|
|
// Basic scoping
|
|
|
|
jQuery.proxy( test, thisObject )();
|
|
|
|
|
|
|
|
// Another take on it
|
|
|
|
jQuery.proxy( thisObject, "method" )();
|
|
|
|
|
|
|
|
// Make sure it doesn't freak out
|
|
|
|
assert.equal( jQuery.proxy( null, thisObject ), undefined, "Make sure no function was returned." );
|
|
|
|
|
|
|
|
// Partial application
|
|
|
|
test2 = function( a ) {
|
|
|
|
assert.equal( a, "pre-applied", "Ensure arguments can be pre-applied." );
|
|
|
|
};
|
|
|
|
jQuery.proxy( test2, null, "pre-applied" )();
|
|
|
|
|
|
|
|
// Partial application w/ normal arguments
|
|
|
|
test3 = function( a, b ) {
|
|
|
|
assert.equal( b, "normal", "Ensure arguments can be pre-applied and passed as usual." );
|
|
|
|
};
|
|
|
|
jQuery.proxy( test3, null, "pre-applied" )( "normal" );
|
|
|
|
|
|
|
|
// Test old syntax
|
|
|
|
test4 = { "meth": function( a ) {
|
|
|
|
assert.equal( a, "boom", "Ensure old syntax works." );
|
|
|
|
} };
|
|
|
|
jQuery.proxy( test4, "meth" )( "boom" );
|
|
|
|
|
|
|
|
// jQuery 1.9 improved currying with `this` object
|
|
|
|
fn = function() {
|
|
|
|
assert.equal( Array.prototype.join.call( arguments, "," ), "arg1,arg2,arg3", "args passed" );
|
|
|
|
assert.equal( this.foo, "bar", "this-object passed" );
|
|
|
|
};
|
|
|
|
cb = jQuery.proxy( fn, null, "arg1", "arg2" );
|
|
|
|
cb.call( thisObject, "arg3" );
|
|
|
|
} );
|
2019-08-22 00:06:26 +00:00
|
|
|
|
2020-01-07 22:59:08 +00:00
|
|
|
QUnit[ jQuery.trim ? "test" : "skip" ]( "trim", function( assert ) {
|
2019-08-22 00:06:26 +00:00
|
|
|
assert.expect( 13 );
|
|
|
|
|
|
|
|
var nbsp = String.fromCharCode( 160 );
|
|
|
|
|
|
|
|
assert.equal( jQuery.trim( "hello " ), "hello", "trailing space" );
|
|
|
|
assert.equal( jQuery.trim( " hello" ), "hello", "leading space" );
|
|
|
|
assert.equal( jQuery.trim( " hello " ), "hello", "space on both sides" );
|
|
|
|
assert.equal( jQuery.trim( " " + nbsp + "hello " + nbsp + " " ), "hello", " " );
|
|
|
|
|
|
|
|
assert.equal( jQuery.trim(), "", "Nothing in." );
|
|
|
|
assert.equal( jQuery.trim( undefined ), "", "Undefined" );
|
|
|
|
assert.equal( jQuery.trim( null ), "", "Null" );
|
|
|
|
assert.equal( jQuery.trim( 5 ), "5", "Number" );
|
|
|
|
assert.equal( jQuery.trim( false ), "false", "Boolean" );
|
|
|
|
|
|
|
|
assert.equal( jQuery.trim( " " ), "", "space should be trimmed" );
|
|
|
|
assert.equal( jQuery.trim( "ipad\xA0" ), "ipad", "nbsp should be trimmed" );
|
|
|
|
assert.equal( jQuery.trim( "\uFEFF" ), "", "zwsp should be trimmed" );
|
|
|
|
assert.equal( jQuery.trim( "\uFEFF \xA0! | \uFEFF" ), "! |", "leading/trailing should be trimmed" );
|
|
|
|
} );
|