1 QUnit
.module( "deprecated", { afterEach
: moduleTeardown
} );
3 if ( includesModule( "deprecated" ) ) {
5 QUnit
.test( "bind/unbind", function( assert
) {
9 "<div><p><span><b>b</b></span></p></div>"
14 .bind( "click", { bindData
: 19 }, function( e
, trig
) {
15 assert
.equal( e
.type
, "click", "correct event type" );
16 assert
.equal( e
.data
.bindData
, 19, "correct trigger data" );
17 assert
.equal( trig
, 42, "correct bind data" );
18 assert
.equal( e
.target
.nodeName
.toLowerCase(), "b", "correct element" );
20 .trigger( "click", [ 42 ] )
26 QUnit
.test( "delegate/undelegate", function( assert
) {
30 "<div><p><span><b>b</b></span></p></div>"
34 .delegate( "b", "click", function( e
) {
35 assert
.equal( e
.type
, "click", "correct event type" );
36 assert
.equal( e
.target
.nodeName
.toLowerCase(), "b", "correct element" );
41 .undelegate( "b", "click" )
45 QUnit
.test( "hover() mouseenter mouseleave", function( assert
) {
49 handler1 = function() { ++times
; },
50 handler2 = function() { ++times
; };
53 .hover( handler1
, handler2
)
54 .mouseenter().mouseleave()
55 .off( "mouseenter", handler1
)
56 .off( "mouseleave", handler2
)
58 .mouseenter().mouseleave()
59 .off( "mouseenter mouseleave", handler1
)
60 .mouseenter().mouseleave();
62 assert
.equal( times
, 4, "hover handlers fired" );
65 QUnit
.test( "trigger() shortcuts", function( assert
) {
68 var counter
, clickCounter
,
69 elem
= jQuery( "<li><a href='#'>Change location</a></li>" ).prependTo( "#firstUL" );
70 elem
.find( "a" ).on( "click", function() {
71 var close
= jQuery( "spanx", this ); // same with jQuery(this).find("span");
72 assert
.equal( close
.length
, 0, "Context element does not exist, length must be zero" );
73 assert
.ok( !close
[ 0 ], "Context element does not exist, direct access to element must return undefined" );
77 // manually clean up detached elements
80 jQuery( "#check1" ).click( function() {
81 assert
.ok( true, "click event handler for checkbox gets fired twice, see trac-815" );
85 jQuery( "#firstp" )[ 0 ].onclick = function() {
88 jQuery( "#firstp" ).click();
89 assert
.equal( counter
, 1, "Check that click, triggers onclick event handler also" );
92 jQuery( "#simon1" )[ 0 ].onclick = function() {
95 jQuery( "#simon1" ).click();
96 assert
.equal( clickCounter
, 1, "Check that click, triggers onclick event handler on an a tag also" );
99 if ( includesModule( "ajax" ) ) {
100 ajaxTest( "Ajax events aliases (with context)", 12, function( assert
) {
101 var context
= document
.createElement( "div" );
103 function event( e
) {
104 assert
.equal( this, context
, e
.type
);
107 function callback( msg
) {
109 assert
.equal( this, context
, "context is preserved on callback " + msg
);
115 jQuery( context
).appendTo( "#foo" )
117 .ajaxComplete( event
)
119 .ajaxSuccess( event
);
122 url
: url( "name.html" ),
124 beforeSend
: callback( "beforeSend" ),
125 success
: callback( "success" ),
126 complete
: callback( "complete" )
128 url
: url( "404.txt" ),
130 beforeSend
: callback( "beforeSend" ),
131 error
: callback( "error" ),
132 complete
: callback( "complete" )
138 QUnit
.test( "Event aliases", function( assert
) {
140 // Explicitly skipping focus/blur events due to their flakiness
141 var $elem
= jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ),
142 aliases
= ( "resize scroll click dblclick mousedown mouseup " +
143 "mousemove mouseover mouseout mouseenter mouseleave change " +
144 "select submit keydown keypress keyup contextmenu" ).split( " " );
145 assert
.expect( aliases
.length
);
147 jQuery
.each( aliases
, function( i
, name
) {
149 // e.g. $(elem).click(...).click();
150 $elem
[ name
]( function( event
) {
151 assert
.equal( event
.type
, name
, "triggered " + name
);
152 } )[ name
]().off( name
);
156 QUnit
.test( "jQuery.proxy", function( assert
) {
159 var test2
, test3
, test4
, fn
, cb
,
161 assert
.equal( this, thisObject
, "Make sure that scope is set properly." );
163 thisObject
= { foo
: "bar", method
: test
};
165 // Make sure normal works
166 test
.call( thisObject
);
169 jQuery
.proxy( test
, thisObject
)();
171 // Another take on it
172 jQuery
.proxy( thisObject
, "method" )();
174 // Make sure it doesn't freak out
175 assert
.equal( jQuery
.proxy( null, thisObject
), undefined, "Make sure no function was returned." );
177 // Partial application
178 test2 = function( a
) {
179 assert
.equal( a
, "pre-applied", "Ensure arguments can be pre-applied." );
181 jQuery
.proxy( test2
, null, "pre-applied" )();
183 // Partial application w/ normal arguments
184 test3 = function( a
, b
) {
185 assert
.equal( b
, "normal", "Ensure arguments can be pre-applied and passed as usual." );
187 jQuery
.proxy( test3
, null, "pre-applied" )( "normal" );
190 test4
= { "meth": function( a
) {
191 assert
.equal( a
, "boom", "Ensure old syntax works." );
193 jQuery
.proxy( test4
, "meth" )( "boom" );
195 // jQuery 1.9 improved currying with `this` object
197 assert
.equal( Array
.prototype.join
.call( arguments
, "," ), "arg1,arg2,arg3", "args passed" );
198 assert
.equal( this.foo
, "bar", "this-object passed" );
200 cb
= jQuery
.proxy( fn
, null, "arg1", "arg2" );
201 cb
.call( thisObject
, "arg3" );