@@ -27,7 +27,7 @@ test( "widget creation", function() {
27
27
} ) ;
28
28
29
29
test ( "element normalization" , function ( ) {
30
- expect ( 10 ) ;
30
+ expect ( 12 ) ;
31
31
var elem ;
32
32
$ . widget ( "ui.testWidget" , { } ) ;
33
33
@@ -65,6 +65,14 @@ test( "element normalization", function() {
65
65
same ( elem . data ( "testWidget" ) , this , "instace stored in .data()" ) ;
66
66
} ;
67
67
$ . ui . testWidget ( { } , "#element-normalization-selector" ) ;
68
+
69
+ $ . ui . testWidget . prototype . defaultElement = null ;
70
+ $ . ui . testWidget . prototype . _create = function ( ) {
71
+ // using strictEqual throws an error (Maximum call stack size exceeded)
72
+ ok ( this . element [ 0 ] === this , "instance as element" ) ;
73
+ ok ( this . element . data ( "testWidget" ) === this , "instance stored in .data()" ) ;
74
+ } ;
75
+ $ . ui . testWidget ( ) ;
68
76
} ) ;
69
77
70
78
test ( "jQuery usage" , function ( ) {
@@ -573,6 +581,28 @@ test( "._trigger() - provide event and ui", function() {
573
581
. testWidget ( "testEvent" ) ;
574
582
} ) ;
575
583
584
+ test ( "._triger() - instance as element" , function ( ) {
585
+ expect ( 4 ) ;
586
+ $ . widget ( "ui.testWidget" , {
587
+ defaultElement : null ,
588
+ testEvent : function ( ) {
589
+ var ui = { foo : "bar" } ;
590
+ this . _trigger ( "foo" , null , ui ) ;
591
+ }
592
+ } ) ;
593
+ var instance = $ . ui . testWidget ( {
594
+ foo : function ( event , ui ) {
595
+ equal ( event . type , "testwidgetfoo" , "event object passed to callback" ) ;
596
+ same ( ui , { foo : "bar" } , "ui object passed to callback" ) ;
597
+ }
598
+ } ) ;
599
+ $ ( instance ) . bind ( "testwidgetfoo" , function ( event , ui ) {
600
+ equal ( event . type , "testwidgetfoo" , "event object passed to event handler" ) ;
601
+ same ( ui , { foo : "bar" } , "ui object passed to event handler" ) ;
602
+ } ) ;
603
+ instance . testEvent ( ) ;
604
+ } ) ;
605
+
576
606
test ( "auto-destroy - .remove()" , function ( ) {
577
607
expect ( 1 ) ;
578
608
$ . widget ( "ui.testWidget" , {
0 commit comments