]> source.dussan.org Git - jquery-ui.git/commitdiff
Widget: Added tests for defaultElement and element normalization between jQuery objec...
authorScott González <scott.gonzalez@gmail.com>
Mon, 24 Jan 2011 00:58:31 +0000 (19:58 -0500)
committerScott González <scott.gonzalez@gmail.com>
Mon, 24 Jan 2011 00:58:31 +0000 (19:58 -0500)
tests/unit/widget/widget_core.js

index 388e078b02f8d82c1803198407c6d81fb4b43279..189b75368bfcb58d9a92c3121e0ce81ce4b1f1ac 100644 (file)
@@ -26,6 +26,47 @@ test( "widget creation", function() {
                "option method copied over from base widget" );
 });
 
+test( "element normalization", function() {
+       expect( 10 );
+       var elem;
+       $.widget( "ui.testWidget", {} );
+
+       $.ui.testWidget.prototype._create = function() {
+               ok( this.element.is( "div" ), "generated div" );
+               same( this.element.data( "testWidget" ), this, "intance stored in .data()" );
+       };
+       $.ui.testWidget();
+
+       $.ui.testWidget.prototype.defaultElement = "<span data-test='pass'>";
+       $.ui.testWidget.prototype._create = function() {
+               ok( this.element.is( "span[data-test=pass]" ), "generated span with properties" );
+               same( this.element.data( "testWidget" ), this, "instace stored in .data()" );
+       };
+       $.ui.testWidget();
+
+       elem = $( "<input>" );
+       $.ui.testWidget.prototype._create = function() {
+               same( this.element[ 0 ], elem[ 0 ], "from element" );
+               same( elem.data( "testWidget" ), this, "instace stored in .data()" );
+       };
+       $.ui.testWidget( {}, elem[ 0 ] );
+
+       elem = $( "<div>" );
+       $.ui.testWidget.prototype._create = function() {
+               same( this.element[ 0 ], elem[ 0 ], "from jQuery object" );
+               same( elem.data( "testWidget" ), this, "instace stored in .data()" );
+       };
+       $.ui.testWidget( {}, elem );
+
+       elem = $( "<div id='element-normalization-selector'></div>" )
+               .appendTo( "#main" );
+       $.ui.testWidget.prototype._create = function() {
+               same( this.element[ 0 ], elem[ 0 ], "from selector" );
+               same( elem.data( "testWidget" ), this, "instace stored in .data()" );
+       };
+       $.ui.testWidget( {}, "#element-normalization-selector" );
+});
+
 test( "jQuery usage", function() {
        expect( 11 );