@@ -449,3 +449,59 @@ TestManager.runIframeTest( "old pre-3.0 jQuery", "core-jquery2.html",
449
449
450
450
assert . ok ( / j Q u e r y 3 / . test ( log ) , "logged: " + log ) ;
451
451
} ) ;
452
+
453
+ QUnit [ jQueryVersionSince ( "3.3.0" ) ? "test" : "skip" ] ( "jQuery.proxy" , function ( assert ) {
454
+ assert . expect ( 10 ) ;
455
+
456
+ var test2 , test3 , test4 , fn , cb ,
457
+ test = function ( ) {
458
+ assert . equal ( this , thisObject , "Make sure that scope is set properly." ) ;
459
+ } ,
460
+ thisObject = { foo : "bar" , method : test } ;
461
+
462
+ expectWarning ( assert , "jQuery.proxy" , 7 , function ( ) {
463
+
464
+ // Make sure normal works
465
+ test . call ( thisObject ) ;
466
+
467
+ // Basic scoping
468
+ jQuery . proxy ( test , thisObject ) ( ) ;
469
+
470
+ // Another take on it
471
+ jQuery . proxy ( thisObject , "method" ) ( ) ;
472
+
473
+ // Make sure it doesn't freak out
474
+ assert . equal ( jQuery . proxy ( null , thisObject ) , undefined ,
475
+ "Make sure no function was returned." ) ;
476
+
477
+ // Partial application
478
+ test2 = function ( a ) {
479
+ assert . equal ( a , "pre-applied" , "Ensure arguments can be pre-applied." ) ;
480
+ } ;
481
+ jQuery . proxy ( test2 , null , "pre-applied" ) ( ) ;
482
+
483
+ // Partial application w/ normal arguments
484
+ test3 = function ( a , b ) {
485
+ assert . equal ( b , "normal" , "Ensure arguments can be pre-applied and passed as usual." ) ;
486
+ } ;
487
+ jQuery . proxy ( test3 , null , "pre-applied" ) ( "normal" ) ;
488
+
489
+ // Test old syntax
490
+ test4 = {
491
+ "meth" : function ( a ) {
492
+ assert . equal ( a , "boom" , "Ensure old syntax works." ) ;
493
+ }
494
+ } ;
495
+ jQuery . proxy ( test4 , "meth" ) ( "boom" ) ;
496
+
497
+ // jQuery 1.9 improved currying with `this` object
498
+ fn = function ( ) {
499
+ assert . equal ( Array . prototype . join . call ( arguments , "," ) ,
500
+ "arg1,arg2,arg3" ,
501
+ "args passed" ) ;
502
+ assert . equal ( this . foo , "bar" , "this-object passed" ) ;
503
+ } ;
504
+ cb = jQuery . proxy ( fn , null , "arg1" , "arg2" ) ;
505
+ cb . call ( thisObject , "arg3" ) ;
506
+ } ) ;
507
+ } ) ;
0 commit comments