QUnit provides a <div id="qunit-fixture"> 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)
});
function createWrappedDiv( text, width ) {
- var $wrapper = $( '<div />' ).css( 'width', width );
- var $div = $( '<div />' ).text( text );
+ var $wrapper = $( '<div>' ).css( 'width', width );
+ var $div = $( '<div>' ).text( text );
$wrapper.append( $div );
return $wrapper;
}
// 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
// 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();
});
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 );
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();
} );
};
test('jquery.delayedBind with data option', function() {
- var $fixture = $('<div>').appendTo('body'),
+ var $fixture = $('<div>').appendTo('#qunit-fixture'),
data = { magic: "beeswax" },
delay = 50;
});
test('jquery.delayedBind without data option', function() {
- var $fixture = $('<div>').appendTo('body'),
+ var $fixture = $('<div>').appendTo('#qunit-fixture'),
data = { magic: "beeswax" },
delay = 50;
'<textarea tabindex="5">Foobar</textarea>' +
'</form>';
- var $testA = $( '<div>' ).html( testEnvironment ).appendTo( 'body' );
+ var $testA = $( '<div>' ).html( testEnvironment ).appendTo( '#qunit-fixture' );
strictEqual( $testA.firstTabIndex(), 2, 'First tabindex should be 2 within this context.' );
var $testB = $( '<div>' );
strictEqual( $testB.firstTabIndex(), null, 'Return null if none available.' );
-
- // Clean up
- $testA.add( $testB ).remove();
});
test( 'lastTabIndex', function() {
'<textarea tabindex="5">Foobar</textarea>' +
'</form>';
- var $testA = $( '<div>' ).html( testEnvironment ).appendTo( 'body' );
+ var $testA = $( '<div>' ).html( testEnvironment ).appendTo( '#qunit-fixture' );
strictEqual( $testA.lastTabIndex(), 9, 'Last tabindex should be 9 within this context.' );
var $testB = $( '<div>' );
strictEqual( $testB.lastTabIndex(), null, 'Return null if none available.' );
-
- // Clean up
- $testA.add( $testB ).remove();
});
expect(1);
var $table = tableCreate( header, data );
- //$( 'body' ).append($table);
// Give caller a chance to set up sorting and manipulate the table.
callback( $table );
test( opt.description, function() {
var tests = 1;
- if (opt.after.selected !== null) {
+ if ( opt.after.selected !== null ) {
tests++;
}
- expect(tests);
+ expect( tests );
- var $fixture = $( '<div id="qunit-fixture"></div>' );
var $textarea = $( '<textarea>' );
- $fixture.append($textarea);
- $( 'body' ).append($fixture);
+ $( '#qunit-fixture' ).append( $textarea );
//$textarea.textSelection( 'setContents', opt.before.text); // this method is actually missing atm...
$textarea.val( opt.before.text ); // won't work with the WikiEditor iframe?
test(options.description, function() {
expect(2);
- var $fixture = $( '<div id="qunit-fixture"></div>' );
var $textarea = $( '<textarea>' ).text(options.text);
- $fixture.append($textarea);
- $( 'body' ).append($fixture);
+ $( '#qunit-fixture' ).append( $textarea );
if (options.mode == 'set') {
$textarea.textSelection('setSelection', {
test( 'addCSS', function() {
expect(3);
- var $testEl = $( '<div>' ).attr( 'id', 'mw-addcsstest' ).appendTo( 'body' );
+ var $testEl = $( '<div>' ).attr( 'id', 'mw-addcsstest' ).appendTo( '#qunit-fixture' );
var style = mw.util.addCSS( '#mw-addcsstest { visibility: hidden; }' );
equal( typeof style, 'object', 'addCSS returned an object' );
equal( $testEl.css( 'visibility' ), 'hidden', 'Added style properties are in effect' );
// Clean up
- $( style.ownerNode )
- .add( $testEl )
- .remove();
+ $( style.ownerNode ).remove();
});
test( 'toggleToc', function() {
'</div>' +
'<ul><li></li></ul>' +
'</td></tr></table>',
- $toc = $(tocHtml).appendTo( 'body' ),
+ $toc = $(tocHtml).appendTo( '#qunit-fixture' ),
$toggleLink = $( '#togglelink' );
strictEqual( $toggleLink.length, 1, 'Toggle link is appended to the page.' );
var actionC = function() {
start();
-
- // Clean up
- $toc.remove();
};
var actionB = function() {
start(); stop();
<h5>Views</h5>\
<ul></ul>\
</div>',
- $mwPanel = $(mwPanel).appendTo( 'body' ),
- $vectorTabs = $(vectorTabs).appendTo( 'body' );
+ $mwPanel = $(mwPanel).appendTo( '#qunit-fixture' ),
+ $vectorTabs = $(vectorTabs).appendTo( '#qunit-fixture' );
var tbRL = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/ResourceLoader',
'ResourceLoader', 't-rl', 'More info about ResourceLoader on MediaWiki.org ', 'l' );
strictEqual( $( caFoo ).find( 'span').length, 1, 'A <span> element should be added for porlets with vectorTabs class.' );
// Clean up
- $( [tbRL, tbMW, tbRLDM, caFoo] )
- .add( $mwPanel )
- .add( $vectorTabs )
- .remove();
+ $( [tbRL, tbMW, tbRLDM, caFoo] ).remove();
});
test( 'jsMessage', function() {