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

Code before:
			done();
		} );
	} );

	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" );
			window.clearTimeout( timeout );
			done();
		};

		var src = baseURL + "mock.php?action=cors";

		// To simulate a cross-origin request
		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 );
	} );

//----------- jQuery.active

	QUnit.test( "jQuery.active", function( assert ) {
		assert.expect( 1 );
		assert.ok( jQuery.active === 0, "ajax active counter should be zero: " + jQuery.active );
	} );

} )();


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.

From my recent investigation: it seems the tests pass in Safari in Karma but not via the PHP setup. On the other hand, they succeed in both modes in Chrome & Firefox.

Code after:
		var done = assert.async();
		jQuery.ajaxSetup( {
			dataFilter: function() {
				return "Hello World";
			}
		} );
		jQuery( "<div></div>" ).load( url( "name.html" ), function( responseText ) {
			assert.strictEqual( jQuery( this ).html(), "Hello World", "Test div was filled with filtered data" );
			assert.strictEqual( responseText, "Hello World", "Test callback receives filtered data" );
			done();
		} );
	} );

	QUnit.test( "jQuery.fn.load( String, Object, Function )", function( assert ) {
		assert.expect( 2 );
		var done = assert.async();
		jQuery( "<div></div>" ).load( url( "mock.php?action=echoHtml" ), {
			"bar": "ok"
		}, function() {
			var $node = jQuery( this );
			assert.strictEqual( $node.find( "#method" ).text(), "POST", "Check method" );
			assert.strictEqual( $node.find( "#data" ).text(), "bar=ok", "Check if data is passed correctly" );
			done();
		} );
	} );

	QUnit.test( "jQuery.fn.load( String, String, Function )", function( assert ) {
		assert.expect( 2 );
		var done = assert.async();

		jQuery( "<div></div>" ).load( url( "mock.php?action=echoHtml" ), "foo=3&bar=ok", function() {
			var $node = jQuery( this );
			assert.strictEqual( $node.find( "#method" ).text(), "GET", "Check method" );
			assert.ok( $node.find( "#query" ).text().match( /foo=3&bar=ok/ ), "Check if a string of data is passed correctly" );
			done();
		} );
	} );

	QUnit.test( "jQuery.fn.load() - callbacks get the correct parameters", function( assert ) {
		assert.expect( 8 );
		var completeArgs = {},
			done = assert.async();

		jQuery.ajaxSetup( {
			success: function( _, status, jqXHR ) {
				completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ];
			},
			error: function( jqXHR, status ) {
				completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ];
			}
		} );