]> source.dussan.org Git - jquery-ui.git/commitdiff
Widget: Throw errors when calling non-existent methods or methods on uninistantiated...
authorScott González <scott.gonzalez@gmail.com>
Fri, 27 Aug 2010 18:48:17 +0000 (14:48 -0400)
committerScott González <scott.gonzalez@gmail.com>
Fri, 27 Aug 2010 18:48:17 +0000 (14:48 -0400)
tests/unit/accordion/accordion_methods.js
tests/unit/dialog/dialog_core.js
tests/unit/dialog/dialog_methods.js
tests/unit/slider/slider.html
tests/unit/slider/slider_methods.js
ui/jquery.ui.widget.js

index 73faff27cb213bae0bdc739c7da0c12614d67a54..96688b59edfdab77455f1d65245d62b7583873ab 100644 (file)
@@ -18,9 +18,6 @@ test("init", function() {
        $('<div></div>').appendTo('body').remove().accordion().remove();
        ok(true, '.accordion() called on disconnected DOMElement - removed');
 
-       $('<div></div>').accordion().accordion("foo").remove();
-       ok(true, 'arbitrary method called after init');
-
        var el = $('<div></div>').accordion();
        var foo = el.accordion("option", "foo");
        el.remove();
index 4618417f0c90c41dac3d5e979314643ac6952fea..aec3e22be93cf1be392770e331247d5e169691a5 100644 (file)
@@ -88,23 +88,6 @@ function margin(el, side) {
 
 module("dialog: core");
 
-test("element types", function() {
-       var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form'
-               + ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr'
-               + ',acronym,code,samp,kbd,var,img,object,hr'
-               + ',input,button,label,select,iframe').split(',');
-
-       $.each(typeNames, function(i) {
-               var typeName = typeNames[i];
-               el = $(document.createElement(typeName)).appendTo('body');
-               (typeName == 'table' && el.append("<tr><td>content</td></tr>"));
-               el.dialog();
-               ok(true, '$("&lt;' + typeName + '/&gt").dialog()');
-               el.dialog("destroy");
-               el.remove();
-       });
-});
-
 test("title id", function() {
        expect(3);
 
index 93d1b25db7b5cb94125862d7e398253b8fc3b34a..a961b4e034c94bf1a465ce358782736afeb47194 100644 (file)
@@ -10,7 +10,7 @@ module("dialog: methods", {
 });
 
 test("init", function() {
-       expect(7);
+       expect(6);
 
        $("<div></div>").appendTo('body').dialog().remove();
        ok(true, '.dialog() called on element');
@@ -24,9 +24,6 @@ test("init", function() {
        $('<div></div>').appendTo('body').remove().dialog().remove();
        ok(true, '.dialog() called on disconnected DOMElement - removed');
 
-       $('<div></div>').dialog().dialog("foo").remove();
-       ok(true, 'arbitrary method called after init');
-
        el = $('<div></div>').dialog();
        var foo = el.dialog("option", "foo");
        el.remove();
@@ -46,9 +43,6 @@ test("destroy", function() {
        $('<div></div>').dialog().dialog("destroy").remove();
        ok(true, '.dialog("destroy") called on disconnected DOMElement');
 
-       $('<div></div>').dialog().dialog("destroy").dialog("foo").remove();
-       ok(true, 'arbitrary method called after destroy');
-
        var expected = $('<div></div>').dialog(),
                actual = expected.dialog('destroy');
        equals(actual, expected, 'destroy is chainable');
index 1ba5f76af22c9efc45f9f36667f632c0f0ce50c1..765340eb560fb5a3e6f3a9e08ff4f1e13b8fbcea 100644 (file)
@@ -15,6 +15,7 @@
        <link rel="stylesheet" href="../../../external/qunit.css" type="text/css"/>
        <script type="text/javascript" src="../../../external/qunit.js"></script>
        <script type="text/javascript" src="../../jquery.simulate.js"></script>
+       <script type="text/javascript" src="../testsuite.js"></script>
 
        <script type="text/javascript" src="slider_core.js"></script>
        <script type="text/javascript" src="slider_defaults.js"></script>
index 567c5de2e6543a72c3df09bfceca667b145f7d8b..77ae6514815d025258bc818e60d806005bf8dfea 100644 (file)
@@ -6,7 +6,7 @@
 module("slider: methods");
 
 test("init", function() {
-       expect(6);
+       expect(5);
 
        $("<div></div>").appendTo('body').slider().remove();
        ok(true, '.slider() called on element');
@@ -17,9 +17,6 @@ test("init", function() {
        $('<div></div>').slider().remove();
        ok(true, '.slider() called on disconnected DOMElement');
 
-       $('<div></div>').slider().slider("foo").remove();
-       ok(true, 'arbitrary method called after init');
-
        var el = $('<div></div>').slider();
        var foo = el.slider("option", "foo");
        el.remove();
@@ -39,9 +36,6 @@ test("destroy", function() {
        $('<div></div>').appendTo('body').remove().slider().slider("destroy").remove();
        ok(true, '.slider("destroy") called on disconnected DOMElement');
 
-       $('<div></div>').slider().slider("destroy").slider("foo").remove();
-       ok(true, 'arbitrary method called after destroy');
-
        var expected = $('<div></div>').slider(),
                actual = expected.slider('destroy');
        equals(actual, expected, 'destroy is chainable');
index ead4af12b5ad4fb834257625507303f17ab7ccca..d08dbb81f7cbbc464d2e44a63a01f99b2f2a6ec1 100644 (file)
@@ -86,10 +86,15 @@ $.widget.bridge = function( name, object ) {
 
                if ( isMethodCall ) {
                        this.each(function() {
-                               var instance = $.data( this, name ),
-                                       methodValue = instance && $.isFunction( instance[options] ) ?
-                                               instance[ options ].apply( instance, args ) :
-                                               instance;
+                               var instance = $.data( this, name );
+                               if ( !instance ) {
+                                       throw "cannot call methods on " + name + " prior to initialization; " +
+                                               "attempted to call method '" + options + "'";
+                               }
+                               if ( !$.isFunction( instance[options] ) ) {
+                                       throw "no such method '" + options + "' for " + name + " widget instance";
+                               }
+                               var methodValue = instance[ options ].apply( instance, args );
                                if ( methodValue !== instance && methodValue !== undefined ) {
                                        returnValue = methodValue;
                                        return false;