aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAvinash R <nashpapa@gmail.com>2012-11-07 10:05:00 -0500
committerScott González <scott.gonzalez@gmail.com>2012-11-07 10:05:00 -0500
commit75bd22eb731f5a81099ad97c88eede3862195fec (patch)
tree30ddbb4fe23de8925973a88de6df92679803c129 /tests
parent979bcab51353d53625c28bbe97dd1ce971ac2a5e (diff)
downloadjquery-ui-75bd22eb731f5a81099ad97c88eede3862195fec.tar.gz
jquery-ui-75bd22eb731f5a81099ad97c88eede3862195fec.zip
Widget: Bridge falls back to name if there is no widgetFullName, and always stores instances in data. Fixed #8775 - Widget: Bridge fails if widgetFullName is not supplied.
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/widget/widget_core.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js
index 7bddc7f5c..acf461a9a 100644
--- a/tests/unit/widget/widget_core.js
+++ b/tests/unit/widget/widget_core.js
@@ -4,6 +4,7 @@ module( "widget factory", {
teardown: function() {
if ( $.ui ) {
delete $.ui.testWidget;
+ delete $.fn.testWidget;
}
}
});
@@ -1305,4 +1306,56 @@ asyncTest( "_delay", function() {
$( "#widget" ).testWidget();
});
+test( "$.widget.bridge()", function() {
+ expect( 9 );
+
+ var instance, ret,
+ elem = $( "<div>" );
+
+ function TestWidget( options, element ) {
+ deepEqual( options, { foo: "bar" }, "options passed" );
+ strictEqual( element, elem[ 0 ], "element passed" );
+ }
+
+ $.extend( TestWidget.prototype, {
+ method: function( param ) {
+ ok( true, "method called via .pluginName(methodName)" );
+ equal( param, "value1",
+ "parameter passed via .pluginName(methodName, param)" );
+ },
+ getter: function() {
+ return "qux";
+ }
+ });
+
+ $.widget.bridge( "testWidget", TestWidget );
+
+ ok( $.isFunction( $.fn.testWidget ), "jQuery plugin was created" );
+
+ strictEqual( elem.testWidget({ foo: "bar" }), elem, "plugin returns original jQuery object" );
+ instance = elem.data( "testWidget" );
+ equal( typeof instance, "object", "instance stored in .data(pluginName)" );
+
+ ret = elem.testWidget( "method", "value1" );
+ equal( ret, elem, "jQuery object returned from method call" );
+
+ ret = elem.testWidget( "getter" );
+ equal( ret, "qux", "getter returns value" );
+});
+
+test( "$.widget.bridge() - widgetFullName", function() {
+ expect( 1 );
+
+ var instance,
+ elem = $( "<div>" );
+
+ function TestWidget() {}
+ TestWidget.prototype.widgetFullName = "custom-widget";
+ $.widget.bridge( "testWidget", TestWidget );
+
+ elem.testWidget();
+ instance = elem.data( "custom-widget" );
+ equal( typeof instance, "object", "instance stored in .data(widgetFullName)" );
+});
+
}( jQuery ) );