From d572221034debcd36ff9b039138d5c96a7e3e348 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Sun, 5 Feb 2012 12:27:20 +0000 Subject: [PATCH] [tests] use core qunit-fixture properly QUnit provides a
by default that is cleared out after each test. * Switch tests to append to the provided #qunit-fixture instead of appending to the body. * Remove redundant .remove() calls, which now happens automatically * Fix jquery.textSelection.test to not cause dozens of elements to be appended to the body with duplicate IDs, which was causing WebFonts test suite to fail (since the DOM can't select multiple elements with the same DOM). (Fixes r92923, r100391) --- .../jquery/jquery.autoEllipsis.test.js | 11 ++++------ .../resources/jquery/jquery.byteLimit.test.js | 4 +--- .../jquery/jquery.delayedBind.test.js | 4 ++-- .../resources/jquery/jquery.tabIndex.test.js | 10 ++-------- .../jquery/jquery.tablesorter.test.js | 1 - .../jquery/jquery.textSelection.test.js | 12 ++++------- .../mediawiki/mediawiki.util.test.js | 20 ++++++------------- 7 files changed, 19 insertions(+), 43 deletions(-) diff --git a/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js b/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js index ba03f2b2ff..6e3713847f 100644 --- a/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js @@ -6,8 +6,8 @@ test( '-- Initial check', function() { }); function createWrappedDiv( text, width ) { - var $wrapper = $( '
' ).css( 'width', width ); - var $div = $( '
' ).text( text ); + var $wrapper = $( '
' ).css( 'width', width ); + var $div = $( '
' ).text( text ); $wrapper.append( $div ); return $wrapper; } @@ -26,7 +26,7 @@ test( 'Position right', function() { // We need this thing to be visible, so append it to the DOM var origText = 'This is a really long random string and there is no way it fits in 100 pixels.'; var $wrapper = createWrappedDiv( origText, '100px' ); - $( 'body' ).append( $wrapper ); + $( '#qunit-fixture' ).append( $wrapper ); $wrapper.autoEllipsis( { position: 'right' } ); // Verify that, and only one, span element was created @@ -47,12 +47,9 @@ test( 'Position right', function() { // Put this text in the span and verify it doesn't fit $span.text( spanTextNew ); // In IE6 width works like min-width, allow IE6's width to be "equal to" - if ( $.browser.msie && Number( $.browser.version ) == 6 ) { + if ( $.browser.msie && Number( $.browser.version ) === 6 ) { gtOrEq( $span.width(), $span.parent().width(), 'Fit is maximal (adding two characters makes it not fit any more) - IE6: Maybe equal to as well due to width behaving like min-width in IE6' ); } else { gt( $span.width(), $span.parent().width(), 'Fit is maximal (adding two characters makes it not fit any more)' ); } - - // Clean up - $wrapper.remove(); }); diff --git a/tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js b/tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js index 2c4dda6332..3346c2d56f 100644 --- a/tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js @@ -46,7 +46,7 @@ var byteLimitTest = function( options ) { test( opt.description, function() { - opt.$input.appendTo( 'body' ); + opt.$input.appendTo( '#qunit-fixture' ); // Simulate pressing keys for each of the sample characters $.addChars( opt.$input, opt.sample ); @@ -66,8 +66,6 @@ var byteLimitTest = function( options ) { equal( newVal, opt.expected, 'New value matches the expected string' ); equal( $.byteLength( newVal ), $.byteLength( opt.expected ), 'Unlimited scenarios are not affected, expected length reached' ); } - - opt.$input.remove(); } ); }; diff --git a/tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js b/tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js index 8688f12e0b..6489a1f176 100644 --- a/tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js @@ -1,5 +1,5 @@ test('jquery.delayedBind with data option', function() { - var $fixture = $('
').appendTo('body'), + var $fixture = $('
').appendTo('#qunit-fixture'), data = { magic: "beeswax" }, delay = 50; @@ -20,7 +20,7 @@ test('jquery.delayedBind with data option', function() { }); test('jquery.delayedBind without data option', function() { - var $fixture = $('
').appendTo('body'), + var $fixture = $('
').appendTo('#qunit-fixture'), data = { magic: "beeswax" }, delay = 50; diff --git a/tests/qunit/suites/resources/jquery/jquery.tabIndex.test.js b/tests/qunit/suites/resources/jquery/jquery.tabIndex.test.js index f26ba7b168..98ff55081c 100644 --- a/tests/qunit/suites/resources/jquery/jquery.tabIndex.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.tabIndex.test.js @@ -18,14 +18,11 @@ test( 'firstTabIndex', function() { '' + ''; - var $testA = $( '
' ).html( testEnvironment ).appendTo( 'body' ); + var $testA = $( '
' ).html( testEnvironment ).appendTo( '#qunit-fixture' ); strictEqual( $testA.firstTabIndex(), 2, 'First tabindex should be 2 within this context.' ); var $testB = $( '
' ); strictEqual( $testB.firstTabIndex(), null, 'Return null if none available.' ); - - // Clean up - $testA.add( $testB ).remove(); }); test( 'lastTabIndex', function() { @@ -39,12 +36,9 @@ test( 'lastTabIndex', function() { '' + ''; - var $testA = $( '
' ).html( testEnvironment ).appendTo( 'body' ); + var $testA = $( '
' ).html( testEnvironment ).appendTo( '#qunit-fixture' ); strictEqual( $testA.lastTabIndex(), 9, 'Last tabindex should be 9 within this context.' ); var $testB = $( '
' ); strictEqual( $testB.lastTabIndex(), null, 'Return null if none available.' ); - - // Clean up - $testA.add( $testB ).remove(); }); diff --git a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js index 31415d61a7..7ecdc4b152 100644 --- a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js @@ -79,7 +79,6 @@ var tableTest = function( msg, header, data, expected, callback ) { expect(1); var $table = tableCreate( header, data ); - //$( 'body' ).append($table); // Give caller a chance to set up sorting and manipulate the table. callback( $table ); diff --git a/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js b/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js index a9a244672e..1b2f30240e 100644 --- a/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js @@ -36,16 +36,14 @@ var encapsulateTest = function( options ) { test( opt.description, function() { var tests = 1; - if (opt.after.selected !== null) { + if ( opt.after.selected !== null ) { tests++; } - expect(tests); + expect( tests ); - var $fixture = $( '
' ); var $textarea = $( '