Bez popisu

deprecated.js 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. QUnit.module( "deprecated", { afterEach: moduleTeardown } );
  2. QUnit[ jQuery.fn.bind ? "test" : "skip" ]( "bind/unbind", function( assert ) {
  3. assert.expect( 4 );
  4. var markup = jQuery(
  5. "<div><p><span><b>b</b></span></p></div>"
  6. );
  7. markup
  8. .find( "b" )
  9. .bind( "click", { bindData: 19 }, function( e, trig ) {
  10. assert.equal( e.type, "click", "correct event type" );
  11. assert.equal( e.data.bindData, 19, "correct trigger data" );
  12. assert.equal( trig, 42, "correct bind data" );
  13. assert.equal( e.target.nodeName.toLowerCase(), "b", "correct element" );
  14. } )
  15. .trigger( "click", [ 42 ] )
  16. .unbind( "click" )
  17. .trigger( "click" )
  18. .remove();
  19. } );
  20. QUnit[ jQuery.fn.delegate ? "test" : "skip" ]( "delegate/undelegate", function( assert ) {
  21. assert.expect( 2 );
  22. var markup = jQuery(
  23. "<div><p><span><b>b</b></span></p></div>"
  24. );
  25. markup
  26. .delegate( "b", "click", function( e ) {
  27. assert.equal( e.type, "click", "correct event type" );
  28. assert.equal( e.target.nodeName.toLowerCase(), "b", "correct element" );
  29. } )
  30. .find( "b" )
  31. .trigger( "click" )
  32. .end()
  33. .undelegate( "b", "click" )
  34. .remove();
  35. } );
  36. QUnit[ jQuery.fn.hover ? "test" : "skip" ]( "hover() mouseenter mouseleave", function( assert ) {
  37. assert.expect( 1 );
  38. var times = 0,
  39. handler1 = function() { ++times; },
  40. handler2 = function() { ++times; };
  41. jQuery( "#firstp" )
  42. .hover( handler1, handler2 )
  43. .mouseenter().mouseleave()
  44. .off( "mouseenter", handler1 )
  45. .off( "mouseleave", handler2 )
  46. .hover( handler1 )
  47. .mouseenter().mouseleave()
  48. .off( "mouseenter mouseleave", handler1 )
  49. .mouseenter().mouseleave();
  50. assert.equal( times, 4, "hover handlers fired" );
  51. } );
  52. QUnit[ jQuery.fn.click ? "test" : "skip" ]( "trigger() shortcuts", function( assert ) {
  53. assert.expect( 5 );
  54. var counter, clickCounter,
  55. elem = jQuery( "<li><a href='#'>Change location</a></li>" ).prependTo( "#firstUL" );
  56. elem.find( "a" ).on( "click", function() {
  57. var close = jQuery( "spanx", this ); // same with jQuery(this).find("span");
  58. assert.equal( close.length, 0, "Context element does not exist, length must be zero" );
  59. assert.ok( !close[ 0 ], "Context element does not exist, direct access to element must return undefined" );
  60. return false;
  61. } ).click();
  62. // manually clean up detached elements
  63. elem.remove();
  64. jQuery( "#check1" ).click( function() {
  65. assert.ok( true, "click event handler for checkbox gets fired twice, see #815" );
  66. } ).click();
  67. counter = 0;
  68. jQuery( "#firstp" )[ 0 ].onclick = function() {
  69. counter++;
  70. };
  71. jQuery( "#firstp" ).click();
  72. assert.equal( counter, 1, "Check that click, triggers onclick event handler also" );
  73. clickCounter = 0;
  74. jQuery( "#simon1" )[ 0 ].onclick = function() {
  75. clickCounter++;
  76. };
  77. jQuery( "#simon1" ).click();
  78. assert.equal( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" );
  79. } );
  80. if ( jQuery.ajax && jQuery.fn.ajaxSend ) {
  81. ajaxTest( "jQuery.ajax() - events with context", 12, function( assert ) {
  82. var context = document.createElement( "div" );
  83. function event( e ) {
  84. assert.equal( this, context, e.type );
  85. }
  86. function callback( msg ) {
  87. return function() {
  88. assert.equal( this, context, "context is preserved on callback " + msg );
  89. };
  90. }
  91. return {
  92. setup: function() {
  93. jQuery( context ).appendTo( "#foo" )
  94. .ajaxSend( event )
  95. .ajaxComplete( event )
  96. .ajaxError( event )
  97. .ajaxSuccess( event );
  98. },
  99. requests: [ {
  100. url: url( "name.html" ),
  101. context: context,
  102. beforeSend: callback( "beforeSend" ),
  103. success: callback( "success" ),
  104. complete: callback( "complete" )
  105. }, {
  106. url: url( "404.txt" ),
  107. context: context,
  108. beforeSend: callback( "beforeSend" ),
  109. error: callback( "error" ),
  110. complete: callback( "complete" )
  111. } ]
  112. };
  113. } );
  114. }
  115. QUnit[ jQuery.fn.click ? "test" : "skip" ]( "Event aliases", function( assert ) {
  116. // Explicitly skipping focus/blur events due to their flakiness
  117. var $elem = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ),
  118. aliases = ( "resize scroll click dblclick mousedown mouseup " +
  119. "mousemove mouseover mouseout mouseenter mouseleave change " +
  120. "select submit keydown keypress keyup contextmenu" ).split( " " );
  121. assert.expect( aliases.length );
  122. jQuery.each( aliases, function( i, name ) {
  123. // e.g. $(elem).click(...).click();
  124. $elem[ name ]( function( event ) {
  125. assert.equal( event.type, name, "triggered " + name );
  126. } )[ name ]().off( name );
  127. } );
  128. } );
  129. QUnit[ jQuery.parseJSON ? "test" : "skip" ]( "jQuery.parseJSON", function( assert ) {
  130. assert.expect( 20 );
  131. assert.strictEqual( jQuery.parseJSON( null ), null, "primitive null" );
  132. assert.strictEqual( jQuery.parseJSON( "0.88" ), 0.88, "Number" );
  133. assert.strictEqual(
  134. jQuery.parseJSON( "\" \\\" \\\\ \\/ \\b \\f \\n \\r \\t \\u007E \\u263a \"" ),
  135. " \" \\ / \b \f \n \r \t ~ \u263A ",
  136. "String escapes"
  137. );
  138. assert.deepEqual( jQuery.parseJSON( "{}" ), {}, "Empty object" );
  139. assert.deepEqual( jQuery.parseJSON( "{\"test\":1}" ), { "test": 1 }, "Plain object" );
  140. assert.deepEqual( jQuery.parseJSON( "[0]" ), [ 0 ], "Simple array" );
  141. assert.deepEqual(
  142. jQuery.parseJSON( "[ \"string\", -4.2, 2.7180e0, 3.14E-1, {}, [], true, false, null ]" ),
  143. [ "string", -4.2, 2.718, 0.314, {}, [], true, false, null ],
  144. "Array of all data types"
  145. );
  146. assert.deepEqual(
  147. jQuery.parseJSON( "{ \"string\": \"\", \"number\": 4.2e+1, \"object\": {}," +
  148. "\"array\": [[]], \"boolean\": [ true, false ], \"null\": null }" ),
  149. { string: "", number: 42, object: {}, array: [ [] ], "boolean": [ true, false ], "null": null },
  150. "Dictionary of all data types"
  151. );
  152. assert.deepEqual( jQuery.parseJSON( "\n{\"test\":1}\t" ), { "test": 1 },
  153. "Leading and trailing whitespace are ignored" );
  154. assert.throws( function() {
  155. jQuery.parseJSON();
  156. }, null, "Undefined raises an error" );
  157. assert.throws( function() {
  158. jQuery.parseJSON( "" );
  159. }, null, "Empty string raises an error" );
  160. assert.throws( function() {
  161. jQuery.parseJSON( "''" );
  162. }, null, "Single-quoted string raises an error" );
  163. assert.throws( function() {
  164. var result = jQuery.parseJSON( "0101" );
  165. // Support: IE <=9 only
  166. // Ensure base-10 interpretation on browsers that erroneously accept leading-zero numbers
  167. if ( result === 101 ) {
  168. throw new Error( "close enough" );
  169. }
  170. }, null, "Leading-zero number raises an error or is parsed as decimal" );
  171. assert.throws( function() {
  172. jQuery.parseJSON( "{a:1}" );
  173. }, null, "Unquoted property raises an error" );
  174. assert.throws( function() {
  175. jQuery.parseJSON( "{'a':1}" );
  176. }, null, "Single-quoted property raises an error" );
  177. assert.throws( function() {
  178. jQuery.parseJSON( "[,]" );
  179. }, null, "Array element elision raises an error" );
  180. assert.throws( function() {
  181. jQuery.parseJSON( "{},[]" );
  182. }, null, "Comma expression raises an error" );
  183. assert.throws( function() {
  184. jQuery.parseJSON( "[]\n,{}" );
  185. }, null, "Newline-containing comma expression raises an error" );
  186. assert.throws( function() {
  187. jQuery.parseJSON( "\"\"\n\"\"" );
  188. }, null, "Automatic semicolon insertion raises an error" );
  189. assert.strictEqual( jQuery.parseJSON( [ 0 ] ), 0, "Input cast to string" );
  190. } );
  191. QUnit[ jQuery.isArray ? "test" : "skip" ]( "jQuery.isArray", function( assert ) {
  192. assert.expect( 1 );
  193. assert.strictEqual( jQuery.isArray, Array.isArray, "Array.isArray equals jQuery.isArray" );
  194. } );
  195. QUnit[ jQuery.nodeName ? "test" : "skip" ]( "jQuery.nodeName", function( assert ) {
  196. assert.expect( 8 );
  197. assert.strictEqual( typeof jQuery.nodeName, "function", "jQuery.nodeName is a function" );
  198. assert.strictEqual(
  199. jQuery.nodeName( document.createElement( "div" ), "div" ),
  200. true,
  201. "Basic usage (true)"
  202. );
  203. assert.strictEqual(
  204. jQuery.nodeName( document.createElement( "div" ), "span" ),
  205. false,
  206. "Basic usage (false)"
  207. );
  208. assert.strictEqual(
  209. jQuery.nodeName( document.createElement( "div" ), "DIV" ),
  210. true,
  211. "Ignores case in the name parameter"
  212. );
  213. assert.strictEqual(
  214. jQuery.nodeName( document.createElement( "section" ), "section" ),
  215. true,
  216. "Works on HTML5 tags (true)"
  217. );
  218. assert.strictEqual(
  219. jQuery.nodeName( document.createElement( "section" ), "article" ),
  220. false,
  221. "Works on HTML5 tags (false)"
  222. );
  223. assert.strictEqual(
  224. jQuery.nodeName( document.createElement( "custom-element" ), "custom-element" ),
  225. true,
  226. "Works on custom elements (true)"
  227. );
  228. assert.strictEqual(
  229. jQuery.nodeName( document.createElement( "custom-element" ), "my-element" ),
  230. false,
  231. "Works on custom elements (true)"
  232. );
  233. } );
  234. QUnit[ jQuery.type ? "test" : "skip" ]( "type", function( assert ) {
  235. assert.expect( 28 );
  236. assert.equal( jQuery.type( null ), "null", "null" );
  237. assert.equal( jQuery.type( undefined ), "undefined", "undefined" );
  238. assert.equal( jQuery.type( true ), "boolean", "Boolean" );
  239. assert.equal( jQuery.type( false ), "boolean", "Boolean" );
  240. assert.equal( jQuery.type( Boolean( true ) ), "boolean", "Boolean" );
  241. assert.equal( jQuery.type( 0 ), "number", "Number" );
  242. assert.equal( jQuery.type( 1 ), "number", "Number" );
  243. assert.equal( jQuery.type( Number( 1 ) ), "number", "Number" );
  244. assert.equal( jQuery.type( "" ), "string", "String" );
  245. assert.equal( jQuery.type( "a" ), "string", "String" );
  246. assert.equal( jQuery.type( String( "a" ) ), "string", "String" );
  247. assert.equal( jQuery.type( {} ), "object", "Object" );
  248. assert.equal( jQuery.type( /foo/ ), "regexp", "RegExp" );
  249. assert.equal( jQuery.type( new RegExp( "asdf" ) ), "regexp", "RegExp" );
  250. assert.equal( jQuery.type( [ 1 ] ), "array", "Array" );
  251. assert.equal( jQuery.type( new Date() ), "date", "Date" );
  252. assert.equal( jQuery.type( new Function( "return;" ) ), "function", "Function" );
  253. assert.equal( jQuery.type( function() {} ), "function", "Function" );
  254. assert.equal( jQuery.type( new Error() ), "error", "Error" );
  255. assert.equal( jQuery.type( window ), "object", "Window" );
  256. assert.equal( jQuery.type( document ), "object", "Document" );
  257. assert.equal( jQuery.type( document.body ), "object", "Element" );
  258. assert.equal( jQuery.type( document.createTextNode( "foo" ) ), "object", "TextNode" );
  259. assert.equal( jQuery.type( document.getElementsByTagName( "*" ) ), "object", "NodeList" );
  260. // Avoid Lint complaints
  261. var MyString = String,
  262. MyNumber = Number,
  263. MyBoolean = Boolean,
  264. MyObject = Object;
  265. assert.equal( jQuery.type( new MyBoolean( true ) ), "boolean", "Boolean" );
  266. assert.equal( jQuery.type( new MyNumber( 1 ) ), "number", "Number" );
  267. assert.equal( jQuery.type( new MyString( "a" ) ), "string", "String" );
  268. assert.equal( jQuery.type( new MyObject() ), "object", "Object" );
  269. } );
  270. QUnit[ jQuery.type && typeof Symbol === "function" ? "test" : "skip" ](
  271. "type for `Symbol`", function( assert ) {
  272. assert.expect( 2 );
  273. assert.equal( jQuery.type( Symbol() ), "symbol", "Symbol" );
  274. assert.equal( jQuery.type( Object( Symbol() ) ), "symbol", "Symbol" );
  275. } );
  276. QUnit[ jQuery.isFunction ? "test" : "skip" ]( "isFunction", function( assert ) {
  277. assert.expect( 20 );
  278. var mystr, myarr, myfunction, fn, obj, nodes, first, input, a;
  279. // Make sure that false values return false
  280. assert.ok( !jQuery.isFunction(), "No Value" );
  281. assert.ok( !jQuery.isFunction( null ), "null Value" );
  282. assert.ok( !jQuery.isFunction( undefined ), "undefined Value" );
  283. assert.ok( !jQuery.isFunction( "" ), "Empty String Value" );
  284. assert.ok( !jQuery.isFunction( 0 ), "0 Value" );
  285. // Check built-ins
  286. assert.ok( jQuery.isFunction( String ), "String Function(" + String + ")" );
  287. assert.ok( jQuery.isFunction( Array ), "Array Function(" + Array + ")" );
  288. assert.ok( jQuery.isFunction( Object ), "Object Function(" + Object + ")" );
  289. assert.ok( jQuery.isFunction( Function ), "Function Function(" + Function + ")" );
  290. // When stringified, this could be misinterpreted
  291. mystr = "function";
  292. assert.ok( !jQuery.isFunction( mystr ), "Function String" );
  293. // When stringified, this could be misinterpreted
  294. myarr = [ "function" ];
  295. assert.ok( !jQuery.isFunction( myarr ), "Function Array" );
  296. // When stringified, this could be misinterpreted
  297. myfunction = { "function": "test" };
  298. assert.ok( !jQuery.isFunction( myfunction ), "Function Object" );
  299. // Make sure normal functions still work
  300. fn = function() {};
  301. assert.ok( jQuery.isFunction( fn ), "Normal Function" );
  302. assert.notOk( jQuery.isFunction( Object.create( fn ) ), "custom Function subclass" );
  303. obj = document.createElement( "object" );
  304. // Some versions of Firefox and Chrome say this is a function
  305. assert.ok( !jQuery.isFunction( obj ), "Object Element" );
  306. // Since 1.3, this isn't supported (#2968)
  307. //assert.ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
  308. nodes = document.body.childNodes;
  309. // Safari says this is a function
  310. assert.ok( !jQuery.isFunction( nodes ), "childNodes Property" );
  311. first = document.body.firstChild;
  312. // Normal elements are reported ok everywhere
  313. assert.ok( !jQuery.isFunction( first ), "A normal DOM Element" );
  314. input = document.createElement( "input" );
  315. input.type = "text";
  316. document.body.appendChild( input );
  317. // Since 1.3, this isn't supported (#2968)
  318. //assert.ok( jQuery.isFunction(input.focus), "A default function property" );
  319. document.body.removeChild( input );
  320. a = document.createElement( "a" );
  321. a.href = "some-function";
  322. document.body.appendChild( a );
  323. // This serializes with the word 'function' in it
  324. assert.ok( !jQuery.isFunction( a ), "Anchor Element" );
  325. document.body.removeChild( a );
  326. // Recursive function calls have lengths and array-like properties
  327. function callme( callback ) {
  328. function fn( response ) {
  329. callback( response );
  330. }
  331. assert.ok( jQuery.isFunction( fn ), "Recursive Function Call" );
  332. fn( { some: "data" } );
  333. }
  334. callme( function() {
  335. callme( function() {} );
  336. } );
  337. } );
  338. QUnit[ jQuery.isFunction ? "test" : "skip" ]( "isFunction(cross-realm function)", function( assert ) {
  339. assert.expect( 1 );
  340. var iframe, doc,
  341. done = assert.async();
  342. // Functions from other windows should be matched
  343. Globals.register( "iframeDone" );
  344. window.iframeDone = function( fn, detail ) {
  345. window.iframeDone = undefined;
  346. assert.ok( jQuery.isFunction( fn ), "cross-realm function" +
  347. ( detail ? " - " + detail : "" ) );
  348. done();
  349. };
  350. iframe = jQuery( "#qunit-fixture" )[ 0 ].appendChild( document.createElement( "iframe" ) );
  351. doc = iframe.contentDocument || iframe.contentWindow.document;
  352. doc.open();
  353. doc.write( "<body onload='window.parent.iframeDone( function() {} );'>" );
  354. doc.close();
  355. } );
  356. supportjQuery.each(
  357. {
  358. GeneratorFunction: "function*() {}",
  359. AsyncFunction: "async function() {}"
  360. },
  361. function( subclass, source ) {
  362. var fn;
  363. try {
  364. fn = Function( "return " + source )();
  365. } catch ( e ) {}
  366. QUnit[ jQuery.isFunction && fn ? "test" : "skip" ]( "isFunction(" + subclass + ")",
  367. function( assert ) {
  368. assert.expect( 1 );
  369. assert.equal( jQuery.isFunction( fn ), true, source );
  370. }
  371. );
  372. }
  373. );
  374. QUnit[ jQuery.isFunction && typeof Symbol === "function" && Symbol.toStringTag ? "test" : "skip" ](
  375. "isFunction(custom @@toStringTag)",
  376. function( assert ) {
  377. assert.expect( 2 );
  378. var obj = {},
  379. fn = function() {};
  380. obj[ Symbol.toStringTag ] = "Function";
  381. fn[ Symbol.toStringTag ] = "Object";
  382. assert.equal( jQuery.isFunction( obj ), false, "function-mimicking object" );
  383. assert.equal( jQuery.isFunction( fn ), true, "object-mimicking function" );
  384. }
  385. );
  386. QUnit[ jQuery.isWindow ? "test" : "skip" ]( "jQuery.isWindow", function( assert ) {
  387. assert.expect( 14 );
  388. assert.ok( jQuery.isWindow( window ), "window" );
  389. assert.ok( jQuery.isWindow( document.getElementsByTagName( "iframe" )[ 0 ].contentWindow ), "iframe.contentWindow" );
  390. assert.ok( !jQuery.isWindow(), "empty" );
  391. assert.ok( !jQuery.isWindow( null ), "null" );
  392. assert.ok( !jQuery.isWindow( undefined ), "undefined" );
  393. assert.ok( !jQuery.isWindow( document ), "document" );
  394. assert.ok( !jQuery.isWindow( document.documentElement ), "documentElement" );
  395. assert.ok( !jQuery.isWindow( "" ), "string" );
  396. assert.ok( !jQuery.isWindow( 1 ), "number" );
  397. assert.ok( !jQuery.isWindow( true ), "boolean" );
  398. assert.ok( !jQuery.isWindow( {} ), "object" );
  399. assert.ok( !jQuery.isWindow( { setInterval: function() {} } ), "fake window" );
  400. assert.ok( !jQuery.isWindow( /window/ ), "regexp" );
  401. assert.ok( !jQuery.isWindow( function() {} ), "function" );
  402. } );
  403. QUnit[ jQuery.camelCase ? "test" : "skip" ]( "jQuery.camelCase()", function( assert ) {
  404. var tests = {
  405. "foo-bar": "fooBar",
  406. "foo-bar-baz": "fooBarBaz",
  407. "girl-u-want": "girlUWant",
  408. "the-4th-dimension": "the-4thDimension",
  409. "-o-tannenbaum": "OTannenbaum",
  410. "-moz-illa": "MozIlla",
  411. "-ms-take": "msTake"
  412. };
  413. assert.expect( 7 );
  414. jQuery.each( tests, function( key, val ) {
  415. assert.equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val );
  416. } );
  417. } );
  418. QUnit[ jQuery.now ? "test" : "skip" ]( "jQuery.now", function( assert ) {
  419. assert.expect( 1 );
  420. assert.ok( typeof jQuery.now() === "number", "jQuery.now is a function" );
  421. } );
  422. QUnit[ jQuery.proxy ? "test" : "skip" ]( "jQuery.proxy", function( assert ) {
  423. assert.expect( 9 );
  424. var test2, test3, test4, fn, cb,
  425. test = function() {
  426. assert.equal( this, thisObject, "Make sure that scope is set properly." );
  427. },
  428. thisObject = { foo: "bar", method: test };
  429. // Make sure normal works
  430. test.call( thisObject );
  431. // Basic scoping
  432. jQuery.proxy( test, thisObject )();
  433. // Another take on it
  434. jQuery.proxy( thisObject, "method" )();
  435. // Make sure it doesn't freak out
  436. assert.equal( jQuery.proxy( null, thisObject ), undefined, "Make sure no function was returned." );
  437. // Partial application
  438. test2 = function( a ) {
  439. assert.equal( a, "pre-applied", "Ensure arguments can be pre-applied." );
  440. };
  441. jQuery.proxy( test2, null, "pre-applied" )();
  442. // Partial application w/ normal arguments
  443. test3 = function( a, b ) {
  444. assert.equal( b, "normal", "Ensure arguments can be pre-applied and passed as usual." );
  445. };
  446. jQuery.proxy( test3, null, "pre-applied" )( "normal" );
  447. // Test old syntax
  448. test4 = { "meth": function( a ) {
  449. assert.equal( a, "boom", "Ensure old syntax works." );
  450. } };
  451. jQuery.proxy( test4, "meth" )( "boom" );
  452. // jQuery 1.9 improved currying with `this` object
  453. fn = function() {
  454. assert.equal( Array.prototype.join.call( arguments, "," ), "arg1,arg2,arg3", "args passed" );
  455. assert.equal( this.foo, "bar", "this-object passed" );
  456. };
  457. cb = jQuery.proxy( fn, null, "arg1", "arg2" );
  458. cb.call( thisObject, "arg3" );
  459. } );
  460. QUnit[ jQuery.isNumeric ? "test" : "skip" ]( "isNumeric", function( assert ) {
  461. assert.expect( 43 );
  462. var t = jQuery.isNumeric,
  463. ToString = function( value ) {
  464. this.toString = function() {
  465. return String( value );
  466. };
  467. };
  468. assert.ok( t( "-10" ), "Negative integer string" );
  469. assert.ok( t( "0" ), "Zero string" );
  470. assert.ok( t( "5" ), "Positive integer string" );
  471. assert.ok( t( -16 ), "Negative integer number" );
  472. assert.ok( t( 0 ), "Zero integer number" );
  473. assert.ok( t( 32 ), "Positive integer number" );
  474. assert.ok( t( "-1.6" ), "Negative floating point string" );
  475. assert.ok( t( "4.536" ), "Positive floating point string" );
  476. assert.ok( t( -2.6 ), "Negative floating point number" );
  477. assert.ok( t( 3.1415 ), "Positive floating point number" );
  478. assert.ok( t( 1.5999999999999999 ), "Very precise floating point number" );
  479. assert.ok( t( 8e5 ), "Exponential notation" );
  480. assert.ok( t( "123e-2" ), "Exponential notation string" );
  481. assert.ok( t( "040" ), "Legacy octal integer literal string" );
  482. assert.ok( t( "0xFF" ), "Hexadecimal integer literal string (0x...)" );
  483. assert.ok( t( "0Xba" ), "Hexadecimal integer literal string (0X...)" );
  484. assert.ok( t( 0xFFF ), "Hexadecimal integer literal" );
  485. if ( +"0b1" === 1 ) {
  486. assert.ok( t( "0b111110" ), "Binary integer literal string (0b...)" );
  487. assert.ok( t( "0B111110" ), "Binary integer literal string (0B...)" );
  488. } else {
  489. assert.ok( true, "Browser does not support binary integer literal (0b...)" );
  490. assert.ok( true, "Browser does not support binary integer literal (0B...)" );
  491. }
  492. if ( +"0o1" === 1 ) {
  493. assert.ok( t( "0o76" ), "Octal integer literal string (0o...)" );
  494. assert.ok( t( "0O76" ), "Octal integer literal string (0O...)" );
  495. } else {
  496. assert.ok( true, "Browser does not support octal integer literal (0o...)" );
  497. assert.ok( true, "Browser does not support octal integer literal (0O...)" );
  498. }
  499. assert.equal( t( new ToString( "42" ) ), false, "Only limited to strings and numbers" );
  500. assert.equal( t( "" ), false, "Empty string" );
  501. assert.equal( t( " " ), false, "Whitespace characters string" );
  502. assert.equal( t( "\t\t" ), false, "Tab characters string" );
  503. assert.equal( t( "abcdefghijklm1234567890" ), false, "Alphanumeric character string" );
  504. assert.equal( t( "xabcdefx" ), false, "Non-numeric character string" );
  505. assert.equal( t( true ), false, "Boolean true literal" );
  506. assert.equal( t( false ), false, "Boolean false literal" );
  507. assert.equal( t( "bcfed5.2" ), false, "Number with preceding non-numeric characters" );
  508. assert.equal( t( "7.2acdgs" ), false, "Number with trailing non-numeric characters" );
  509. assert.equal( t( undefined ), false, "Undefined value" );
  510. assert.equal( t( null ), false, "Null value" );
  511. assert.equal( t( NaN ), false, "NaN value" );
  512. assert.equal( t( Infinity ), false, "Infinity primitive" );
  513. assert.equal( t( Number.POSITIVE_INFINITY ), false, "Positive Infinity" );
  514. assert.equal( t( Number.NEGATIVE_INFINITY ), false, "Negative Infinity" );
  515. assert.equal( t( new ToString( "Devo" ) ), false, "Custom .toString returning non-number" );
  516. assert.equal( t( {} ), false, "Empty object" );
  517. assert.equal( t( [] ), false, "Empty array" );
  518. assert.equal( t( [ 42 ] ), false, "Array with one number" );
  519. assert.equal( t( function() {} ), false, "Instance of a function" );
  520. assert.equal( t( new Date() ), false, "Instance of a Date" );
  521. } );
  522. QUnit[ jQuery.isNumeric && typeof Symbol === "function" ? "test" : "skip" ](
  523. "isNumeric(Symbol)", function( assert ) {
  524. assert.expect( 2 );
  525. assert.equal( jQuery.isNumeric( Symbol() ), false, "Symbol" );
  526. assert.equal( jQuery.isNumeric( Object( Symbol() ) ), false, "Symbol inside an object" );
  527. } );
  528. QUnit[ jQuery.trim ? "test" : "skip" ]( "trim", function( assert ) {
  529. assert.expect( 13 );
  530. var nbsp = String.fromCharCode( 160 );
  531. assert.equal( jQuery.trim( "hello " ), "hello", "trailing space" );
  532. assert.equal( jQuery.trim( " hello" ), "hello", "leading space" );
  533. assert.equal( jQuery.trim( " hello " ), "hello", "space on both sides" );
  534. assert.equal( jQuery.trim( " " + nbsp + "hello " + nbsp + " " ), "hello", "&nbsp;" );
  535. assert.equal( jQuery.trim(), "", "Nothing in." );
  536. assert.equal( jQuery.trim( undefined ), "", "Undefined" );
  537. assert.equal( jQuery.trim( null ), "", "Null" );
  538. assert.equal( jQuery.trim( 5 ), "5", "Number" );
  539. assert.equal( jQuery.trim( false ), "false", "Boolean" );
  540. assert.equal( jQuery.trim( " " ), "", "space should be trimmed" );
  541. assert.equal( jQuery.trim( "ipad\xA0" ), "ipad", "nbsp should be trimmed" );
  542. assert.equal( jQuery.trim( "\uFEFF" ), "", "zwsp should be trimmed" );
  543. assert.equal( jQuery.trim( "\uFEFF \xA0! | \uFEFF" ), "! |", "leading/trailing should be trimmed" );
  544. } );