diff options
author | Scott González <scott.gonzalez@gmail.com> | 2011-02-10 21:25:50 -0500 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-02-10 21:25:50 -0500 |
commit | 6096aed0a38948fe02a697d0f5349c6903c90e47 (patch) | |
tree | 95943964405e828aa4b9e5a8d244aa4563d82680 /tests | |
parent | fb35d4e5c5638dac72cb53ed37ee240b2fe91f46 (diff) | |
download | jquery-ui-6096aed0a38948fe02a697d0f5349c6903c90e47.tar.gz jquery-ui-6096aed0a38948fe02a697d0f5349c6903c90e47.zip |
Widget: Fixed super methods with deep inheritance chains.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/testsuite.js | 2 | ||||
-rw-r--r-- | tests/unit/widget/widget_core.js | 62 |
2 files changed, 41 insertions, 23 deletions
diff --git a/tests/unit/testsuite.js b/tests/unit/testsuite.js index 3e4ac5bbf..b3748d8ee 100644 --- a/tests/unit/testsuite.js +++ b/tests/unit/testsuite.js @@ -24,8 +24,6 @@ function testWidgetDefaults( widget, defaults ) { var privateMethods = [ "_createWidget", - "_super", - "_superApply", "destroy", "option", "enable", diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index 186c407ed..b92885fd9 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -34,7 +34,7 @@ test( "element normalization", function() { }; $.ui.testWidget(); - $.ui.testWidget.prototype.defaultElement = "<span data-test='pass'>"; + $.ui.testWidget.prototype.defaultElement = "<span data-test='pass'></span>"; $.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()" ); @@ -224,12 +224,12 @@ test( "._getCreateOptions()", function() { options: { option1: "valuex", option2: "valuex", - option3: "value3", + option3: "value3" }, _getCreateOptions: function() { return { option1: "override1", - option2: "overideX", + option2: "overideX" }; }, _create: function() { @@ -274,55 +274,75 @@ test( "re-init", function() { }); test( "._super()", function() { - expect( 6 ); + expect( 9 ); var instance; $.widget( "ui.testWidget", { method: function( a, b ) { - same( this, instance, "this is correct in super widget" ); - same( a, 5, "parameter passed to super widget" ); - same( b, 10, "second parameter passed to super widget" ); + same( this, instance, "this is correct in testWidget" ); + same( a, 5, "parameter passed to testWidget" ); + same( b, 20, "second parameter passed to testWidget" ); return a + b; } }); $.widget( "ui.testWidget2", $.ui.testWidget, { + method: function( a, b ) { + same( this, instance, "this is correct in testWidget2" ); + same( a, 5, "parameter passed to testWidget2" ); + same( b, 10, "parameter passed to testWidget2" ); + return this._super( "method", a, b*2 ); + } + }); + + $.widget( "ui.testWidget3", $.ui.testWidget2, { method: function( a ) { - same( this, instance, "this is correct in widget" ); - same( a, 5, "parameter passed to widget" ); + same( this, instance, "this is correct in testWidget3" ); + same( a, 5, "parameter passed to testWidget3" ); var ret = this._super( "method", a, a*2 ); - same( ret, 15, "super returned value" ); + same( ret, 25, "super returned value" ); } }); - instance = $( "<div>" ).testWidget2().data( "testWidget2" ); + instance = $( "<div>" ).testWidget3().data( "testWidget3" ); instance.method( 5 ); + delete $.ui.testWidget3; delete $.ui.testWidget2; }); test( "._superApply()", function() { - expect( 7 ); + expect( 10 ); var instance; $.widget( "ui.testWidget", { method: function( a, b ) { - same( this, instance, "this is correct in super widget" ); - same( a, 5, "parameter passed to super widget" ); - same( b, 10, "second parameter passed to super widget" ); + same( this, instance, "this is correct in testWidget" ); + same( a, 5, "parameter passed to testWidget" ); + same( b, 10, "second parameter passed to testWidget" ); return a + b; } }); $.widget( "ui.testWidget2", $.ui.testWidget, { method: function( a, b ) { - same( this, instance, "this is correct in widget" ); - same( a, 5, "parameter passed to widget" ); - same( b, 10, "second parameter passed to widget" ); + same( this, instance, "this is correct in testWidget2" ); + same( a, 5, "parameter passed to testWidget2" ); + same( b, 10, "second parameter passed to testWidget2" ); + return this._superApply( "method", arguments ); + } + }); + + $.widget( "ui.testWidget3", $.ui.testWidget2, { + method: function( a, b ) { + same( this, instance, "this is correct in testWidget3" ); + same( a, 5, "parameter passed to testWidget3" ); + same( b, 10, "second parameter passed to testWidget3" ); var ret = this._superApply( "method", arguments ); same( ret, 15, "super returned value" ); } }); - instance = $( "<div>" ).testWidget2().data( "testWidget2" ); + instance = $( "<div>" ).testWidget3().data( "testWidget3" ); instance.method( 5, 10 ); + delete $.ui.testWidget3; delete $.ui.testWidget2; }); @@ -829,7 +849,7 @@ test( "redefine", function() { equal( str, "bar", "original invoked with correct parameter" ); } }); - var ctor = $.ui.testWidget; + $.ui.testWidget.foo = "bar"; $.widget( "ui.testWidget", $.ui.testWidget, { method: function( str ) { equal( str, "foo", "new invoked with correct parameter" ); @@ -839,7 +859,7 @@ test( "redefine", function() { var instance = new $.ui.testWidget(); instance.method( "foo" ); - equal( $.ui.testWidget, ctor, "constructor did not change" ); + equal( $.ui.testWidget.foo, "bar", "static properties remain" ); }); }( jQuery ) ); |