diff options
Diffstat (limited to 'tests/unit/testsuite.js')
-rw-r--r-- | tests/unit/testsuite.js | 78 |
1 files changed, 54 insertions, 24 deletions
diff --git a/tests/unit/testsuite.js b/tests/unit/testsuite.js index d152f84cd..9724a946f 100644 --- a/tests/unit/testsuite.js +++ b/tests/unit/testsuite.js @@ -1,39 +1,69 @@ -function testWidgetDefaults(widget, defaults) { - var pluginDefaults = $.extend({}, - $.ui[widget].prototype.options - ); - +(function() { + +function testWidgetDefaults( widget, defaults ) { + var pluginDefaults = $.ui[ widget ].prototype.options; + // ensure that all defaults have the correct value - test('defined defaults', function() { - $.each(defaults, function(key, val) { - if ($.isFunction(val)) { - ok(val !== undefined, key); + test( "defined defaults", function() { + $.each( defaults, function( key, val ) { + if ( $.isFunction( val ) ) { + ok( $.isFunction( pluginDefaults[ key ] ), key ); return; } - same(pluginDefaults[key], val, key); + same( pluginDefaults[ key ], val, key ); }); }); - + // ensure that all defaults were tested - test('tested defaults', function() { - $.each(pluginDefaults, function(key, val) { - ok(key in defaults, key); + test( "tested defaults", function() { + $.each( pluginDefaults, function( key, val ) { + ok( key in defaults, key ); }); }); } -function testWidgetOverrides(widget) { - test('$.widget overrides', function() { - $.each(['_widgetInit', 'option', '_trigger'], function(i, method) { - ok($.Widget.prototype[method] == $.ui[widget].prototype[method], - 'should not override ' + method); +var privateMethods = [ + "_createWidget", + "_super", + "_superApply", + "destroy", + "option", + "enable", + "disable", + "_trigger" +]; + +function testWidgetOverrides( widget ) { + if ( $.uiBackCompat === false ) { + test( "$.widget overrides", function() { + $.each( privateMethods, function( i, method ) { + strictEqual( $.ui[ widget ].prototype[ method ], + $.Widget.prototype[ method ], "should not override " + method ); + }); }); - }); + } } -function commonWidgetTests(widget, settings) { - module(widget + ": common widget"); +function testBasicUsage( widget ) { + test( "basic usage", function() { + var defaultElement = $.ui[ widget ].prototype.defaultElement; + $( defaultElement ).appendTo( "body" )[ widget ]().remove(); + ok( true, "initialized on element" ); - testWidgetDefaults(widget, settings.defaults); - testWidgetOverrides(widget); + $( defaultElement )[ widget ]().remove(); + ok( true, "initialized on disconnected DOMElement - never connected" ); + + $( defaultElement ).appendTo( "body" ).remove()[ widget ]().remove(); + ok( true, "initialized on disconnected DOMElement - removed" ); + }); } + +window.commonWidgetTests = function( widget, settings ) { + module( widget + ": common widget" ); + + testWidgetDefaults( widget, settings.defaults ); + testWidgetOverrides( widget ); + testBasicUsage( widget ); +}; + +}()); |