From e94aa80586e6047a447db291af29142dec1d0e8b Mon Sep 17 00:00:00 2001 From: Krinkle Date: Wed, 18 May 2011 17:58:38 +0000 Subject: [PATCH] QUnit test suite improvements * [jquery.autoEllipsis.js] Adding check to verify that span exists and is the only and direct child * [mediawiki.js] Deleting window.awesome after the test is ran. This will make the test suite pass QUnit's "No globals" mode which is useful to detect if a module introduced an (implied) global variable. --- .../test/unit/jquery/jquery.autoEllipsis.js | 22 ++++++++++--------- resources/test/unit/mediawiki/mediawiki.js | 4 ++++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/resources/test/unit/jquery/jquery.autoEllipsis.js b/resources/test/unit/jquery/jquery.autoEllipsis.js index a613387e05..e0d5b98f63 100644 --- a/resources/test/unit/jquery/jquery.autoEllipsis.js +++ b/resources/test/unit/jquery/jquery.autoEllipsis.js @@ -25,23 +25,25 @@ test( 'Position right', function() { var origText = 'This is a really long random string and there is no way it fits in 100 pixels.'; var $wrapper = createWrappedDiv( origText ); $( 'body' ).append( $wrapper ); - // Autoellipse it $wrapper.autoEllipsis( { position: 'right' } ); - // Turn on word wrapping - var $span = $wrapper.find( 'span' ); + + // Verify that, and only one, span element was created + var $span = $wrapper.find( '> span' ); + deepEqual( $span.length, 1, 'autoEllipsis wrapped the contents in a span element' ); + + // Check that the text fits by turning on word wrapping $span.css( 'whiteSpace', 'nowrap' ); - - // Check that the text fits - ok( $span.width() <= $span.parent().width(), "text fits (span's width is no larger than its parent's width)" ); - + ok( $span.width() <= $span.parent().width(), "Text fits (span's width is no larger than its parent's width)" ); + // Add one character using scary black magic var spanText = $span.text(); var d = findDivergenceIndex( origText, spanText ); spanText = spanText.substr( 0, d ) + origText[d] + '...'; - + // Put this text in the span and verify it doesn't fit $span.text( spanText ); - ok( $span.width() > $span.parent().width(), "fit is maximal (adding one character makes it not fit any more)" ); - + ok( $span.width() > $span.parent().width(), 'Fit is maximal (adding one character makes it not fit any more)' ); + + // Clean up $wrapper.remove(); }); diff --git a/resources/test/unit/mediawiki/mediawiki.js b/resources/test/unit/mediawiki/mediawiki.js index 04238877d7..bcd8a5a5be 100644 --- a/resources/test/unit/mediawiki/mediawiki.js +++ b/resources/test/unit/mediawiki/mediawiki.js @@ -71,6 +71,10 @@ test( 'mw.loader', function(){ mw.loader.using( 'is.awesome', function(){ start(); deepEqual( window.awesome, true, 'Implementing a module, is the callback timed properly ?'); + + // Clean up + delete window.awesome; + }, function(){ start(); deepEqual( 'mw.loader.using error callback fired', true, 'Implementing a module, is the callback timed properly ?'); -- 2.20.1