jquery-ui/tests/unit/testsuite.js

73 lines
1.8 KiB
JavaScript
Raw Normal View History

2011-01-25 00:20:09 +00:00
(function() {
function testWidgetDefaults( widget, defaults ) {
var pluginDefaults = $.ui[ widget ].prototype.options;
// ensure that all defaults have the correct value
2011-01-25 00:20:09 +00:00
test( "defined defaults", function() {
$.each( defaults, function( key, val ) {
if ( $.isFunction( val ) ) {
ok( $.isFunction( pluginDefaults[ key ] ), key );
return;
}
2011-01-25 00:20:09 +00:00
same( pluginDefaults[ key ], val, key );
2009-04-17 21:28:37 +00:00
});
});
2011-01-25 00:20:09 +00:00
2009-04-17 21:28:37 +00:00
// ensure that all defaults were tested
2011-01-25 00:20:09 +00:00
test( "tested defaults", function() {
$.each( pluginDefaults, function( key, val ) {
ok( key in defaults, key );
2009-04-17 21:28:37 +00:00
});
});
}
2011-01-25 00:20:09 +00:00
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 );
});
2009-04-17 21:28:37 +00:00
});
}
}
2011-01-25 00:20:09 +00:00
function testBasicUsage( widget ) {
test( "basic usage", function() {
var defaultElement = $.ui[ widget ].prototype.defaultElement;
$( defaultElement ).appendTo( "body" )[ widget ]().remove();
ok( true, "initialized on element" );
$( defaultElement )[ widget ]().remove();
2011-01-25 00:20:09 +00:00
ok( true, "initialized on disconnected DOMElement - never connected" );
$( defaultElement ).appendTo( "body" ).remove()[ widget ]().remove();
2011-01-25 00:20:09 +00:00
ok( true, "initialized on disconnected DOMElement - removed" );
});
}
2011-01-25 00:20:09 +00:00
window.commonWidgetTests = function( widget, settings ) {
module( widget + ": common widget" );
testWidgetDefaults( widget, settings.defaults );
testWidgetOverrides( widget );
testBasicUsage( widget );
test( "version", function() {
ok( "version" in $.ui[ widget ], "version property exists" );
});
2011-01-25 00:20:09 +00:00
};
}());