This may be obvious to everyone else but I didn't find it by searching, so posting both the question and one possible answer here.
Background:
- Custom JQuery UI widget using widget factory
- In the widget, some elements get hidden or shown based on other data/options.
- Creating unit tests to verify they are being shown/hidden correctly.
- I thought that my unit tests could each create their own element in memory, similar to this old answer.
Stripped out the actual widget part from this example:
test( 'show/hide', 1, function() {
var somecondition = true;
var div = $( '<div/>' ).hide();
if (somecondition) div.show();
equal( somecondition, div.is( ":visible" ) );
});
The test fails because jQuery always reports div.is( ":visible" )
as false. I thought that using div.css('display') == 'none'
would be a workaround. Unfortunately, this worked in Chrome but not Firefox.