The problem was that jQuery is smart enough to know that even if a particular element has said it's visible, it might not actually be visible if (for example):
- It was never added to the DOM
- The DOM element (or parent/grandparent/etc) it was appended to is not actually visible
So in order for the unit tests to work, I need to have a real div in the test harness html, attach the widget to it, and then call a destroy at the end.
test( 'show/hide', 1, function() {
var somecondition = true;
var div = $( '#someid' ).hide();
if (somecondition) div.show();
equal( somecondition, div.is( ":visible" ) );
});
I was hoping for a different approach (and maybe someone will come along and provide another answer), but I'm not very hopeful, seeing as this is the approach that JQueryUI uses in their own QUnit tests:
test( "search, close", function() {
//SNIP
// Note the use of a real element here:
element = $( "#autocomplete" ).autocomplete({
source: data,
minLength: 0
}),
menu = element.autocomplete( "widget" );
//SNIP
ok( menu.is( ":visible" ), "menu is visible after search" );
//SNIP
});