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

Code before:
	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." );

	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 = $$;
} );


Review comment (bug):
This assertion fires for me in Safari 13, Edge 18 & IE 11. It correctly doesn't fire only in Firefox 72 & Chrome 79.

We need to figure out why it fails in other browsers. For IE we might have to skip the test as it doesn't support the crossorigin attribute (by switching from `QUnit.test` to `QUnit.testUnlessIE`). Other browsers should pass it, though.

Code after:
	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 );

	var pass, iframe, doc, parentObj, childObj, deep,
		fn = function() {};

	// The use case that we want to match
	assert.ok( jQuery.isPlainObject( {} ), "{}" );
	assert.ok( jQuery.isPlainObject( new window.Object() ), "new Object" );
	assert.ok( jQuery.isPlainObject( { constructor: fn } ),
		"plain object with constructor property" );
	assert.ok( jQuery.isPlainObject( { constructor: "foo" } ),
		"plain object with primitive constructor property" );