Repository: jquery/jquery
File: test/unit/core.js (JavaScript)

Code before:
QUnit.test( "globalEval execution after script injection (#7862)", function( assert ) {
	assert.expect( 1 );

	var now,
		script = document.createElement( "script" );

	script.src = baseURL + "mock.php?action=wait&wait=2&script=1";

	now = Date.now();
	document.body.appendChild( script );

	jQuery.globalEval( "var strictEvalTest = " + Date.now() + ";" );
	assert.ok( window.strictEvalTest - now < 500, "Code executed synchronously" );
} );

QUnit.test( "jQuery.append with crossOrigin attribute", function( assert ) {
	var done = assert.async();
	assert.expect( 1 );

	var timeout = null;

	Globals.register( "corsCallback" );
	window.corsCallback = function( response ) {
		assert.ok( response === true, "Cors" );

		if ( timeout != null ) {
			window.clearTimeout( timeout );
		}

		done();
	};

	var src = baseURL + "mock.php?action=cors";
	src = src.replace( "localhost", "127.0.0.1" );
	var html = "<script type=\"text/javascript\" src=\"" + src + "\" crossOrigin=\"anonymous\"><\/script>";

	jQuery( document.body ).append( html );
	timeout = window.setTimeout( function() {
		assert.ok( false, "Cors" );
		done();
	}, 2000 );
} );

QUnit.test( "noConflict", function( assert ) {
	assert.expect( 7 );

	var $$ = jQuery;

	assert.strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" );
	assert.strictEqual( window[ "jQuery" ], $$, "Make sure jQuery wasn't touched." );
	assert.strictEqual( window[ "$" ], original$, "Make sure $ was reverted." );

Review comment (suggestion):
The `if` is not necessary, `clearTimeout` on `null` is a no-op.

Code after:
QUnit.test( "globalEval execution after script injection (#7862)", function( assert ) {
	assert.expect( 1 );

	var now,
		script = document.createElement( "script" );

	script.src = baseURL + "mock.php?action=wait&wait=2&script=1";

	now = Date.now();
	document.body.appendChild( script );

	jQuery.globalEval( "var strictEvalTest = " + Date.now() + ";" );
	assert.ok( window.strictEvalTest - now < 500, "Code executed synchronously" );
} );

testIframe(
	"globalEval with custom document context",
	"core/globaleval-context.html",
	function( assert, framejQuery, frameWindow, frameDocument ) {
		assert.expect( 2 );

		jQuery.globalEval( "window.scriptTest = true;", {}, frameDocument );
		assert.ok( !window.scriptTest, "script executed in iframe context" );
		assert.ok( frameWindow.scriptTest, "script executed in iframe context" );
	}
);


QUnit.test( "noConflict", function( assert ) {
	assert.expect( 7 );

	var $$ = jQuery;

	assert.strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" );
	assert.strictEqual( window[ "jQuery" ], $$, "Make sure jQuery wasn't touched." );
	assert.strictEqual( window[ "$" ], original$, "Make sure $ was reverted." );

	jQuery = $ = $$;

	assert.strictEqual( jQuery.noConflict( true ), $$, "noConflict returned the jQuery object" );
	assert.strictEqual( window[ "jQuery" ], originaljQuery, "Make sure jQuery was reverted." );
	assert.strictEqual( window[ "$" ], original$, "Make sure $ was reverted." );
	assert.ok( $$().pushStack( [] ), "Make sure that jQuery still works." );

	window[ "jQuery" ] = jQuery = $$;
} );

QUnit.test( "isPlainObject", function( assert ) {
	var done = assert.async();

	assert.expect( 23 );