mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Tests: More improvments for testrunner
Conform to style guide and simplify it
This commit is contained in:
parent
92cff8b1a3
commit
8e5d1caf7a
@ -112,13 +112,13 @@ this.createXMLFragment = function() {
|
||||
|
||||
fireNative = document.createEvent ?
|
||||
function( node, type ) {
|
||||
var event = document.createEvent('HTMLEvents');
|
||||
var event = document.createEvent( "HTMLEvents" );
|
||||
|
||||
event.initEvent( type, true, true );
|
||||
node.dispatchEvent( event );
|
||||
} :
|
||||
function( node, type ) {
|
||||
var event = document.createEventObject();
|
||||
node.fireEvent( 'on' + type, event );
|
||||
node.fireEvent( "on" + type, document.createEventObject() );
|
||||
};
|
||||
|
||||
/**
|
||||
@ -233,31 +233,28 @@ this.testIframe = function( fileName, name, fn ) {
|
||||
};
|
||||
|
||||
this.testIframeWithCallback = function( title, fileName, func ) {
|
||||
|
||||
test( title, function() {
|
||||
asyncTest( title, 1, function() {
|
||||
var iframe;
|
||||
|
||||
// Expect one assertion, but allow overrides
|
||||
expect( 1 );
|
||||
|
||||
stop();
|
||||
window.iframeCallback = function() {
|
||||
var self = this,
|
||||
args = arguments;
|
||||
var args = arguments;
|
||||
|
||||
setTimeout(function() {
|
||||
window.iframeCallback = undefined;
|
||||
this.iframeCallback = undefined;
|
||||
|
||||
iframe.remove();
|
||||
func.apply( self, args );
|
||||
func.apply( this, args );
|
||||
func = function() {};
|
||||
|
||||
start();
|
||||
}, 0 );
|
||||
});
|
||||
};
|
||||
iframe = jQuery( "<div/>" ).css({ position: "absolute", width: "500px", left: "-600px" })
|
||||
.append( jQuery( "<iframe/>" ).attr( "src", url( "./data/" + fileName ) ) )
|
||||
.appendTo( "#qunit-fixture" );
|
||||
});
|
||||
};
|
||||
window.iframeCallback = undefined;
|
||||
this.iframeCallback = undefined;
|
||||
|
||||
// Tests are always loaded async
|
||||
QUnit.config.autostart = false;
|
||||
|
@ -1,19 +1,14 @@
|
||||
define(function() {
|
||||
(function() {
|
||||
|
||||
// Allow subprojects to test against their own fixtures
|
||||
var qunitModule = QUnit.module,
|
||||
qunitTest = QUnit.test,
|
||||
// Store the old counts so that we only assert on tests that have actually leaked,
|
||||
// instead of asserting every time a test has leaked sometime in the past
|
||||
oldCacheLength = 0,
|
||||
var oldCacheLength = 0,
|
||||
oldActive = 0,
|
||||
|
||||
expectedDataKeys = {},
|
||||
reset,
|
||||
splice = [].splice,
|
||||
ajaxSettings = jQuery.ajaxSettings;
|
||||
|
||||
|
||||
/**
|
||||
* QUnit configuration
|
||||
*/
|
||||
@ -90,8 +85,7 @@ QUnit.config.urlConfig.push({
|
||||
* teardown function on all modules' lifecycle object.
|
||||
*/
|
||||
window.moduleTeardown = function() {
|
||||
var i,
|
||||
expectedKeys, actualKeys,
|
||||
var i, expectedKeys, actualKeys,
|
||||
cacheLength = 0;
|
||||
|
||||
// Only look for jQuery data problems if this test actually
|
||||
@ -143,18 +137,7 @@ window.moduleTeardown = function() {
|
||||
}
|
||||
};
|
||||
|
||||
QUnit.done(function() {
|
||||
// Remove our own fixtures outside #qunit-fixture
|
||||
supportjQuery("#qunit ~ *").remove();
|
||||
});
|
||||
|
||||
// jQuery-specific post-test cleanup
|
||||
reset = function () {
|
||||
|
||||
// Ensure jQuery events and data on the fixture are properly removed
|
||||
jQuery("#qunit-fixture").empty();
|
||||
// ...even if the jQuery under test has a broken .empty()
|
||||
supportjQuery("#qunit-fixture").empty();
|
||||
QUnit.testDone(function() {
|
||||
|
||||
// Reset internal jQuery state
|
||||
jQuery.event.global = {};
|
||||
@ -166,10 +149,7 @@ reset = function () {
|
||||
|
||||
// Cleanup globals
|
||||
Globals.cleanup();
|
||||
jQuery("#qunit-fixture")[0].innerHTML = QUnit.config.fixture;
|
||||
};
|
||||
|
||||
QUnit.testDone(reset);
|
||||
});
|
||||
|
||||
// Register globals for cleanup and the cleanup code itself
|
||||
window.Globals = (function() {
|
||||
@ -192,4 +172,4 @@ window.Globals = (function() {
|
||||
};
|
||||
})();
|
||||
|
||||
});
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user