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

Code before:

	QUnit.test( "jQuery[get|post]( options ) - simple with xml", function( assert ) {
		assert.expect( 2 );
		var done = assert.async();

		jQuery.when.apply( jQuery,
			jQuery.map( [ "get", "post" ], function( method ) {
				return jQuery[ method ]( {
					url: url( "mock.php?action=xml" ),
					data: {
						cal: "5-2"
					},
					success: function( xml ) {
						jQuery( "math", xml ).each( function() {
							assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
						} );
					}
				} );
			} )
		).always( function() {
			done();
		} );
	} );

	// We need to simulate cross-domain requests with the feature that both 127.0.0.1 and localhost point to the mock http server
	// So skip the the test if we are not in localhost.
	QUnit[ ( !QUnit.isSwarm || location.hostname === "localhost" ) ? "test" : "skip" ](
		"jQuery.append with crossorigin attribute", function( assert ) {
		assert.expect( 1 );

		var done = assert.async(),
				timeout;

		Globals.register( "corsCallback" );
		window.corsCallback = function( response ) {
			assert.ok( response === true, "Callback fired" );
			window.clearTimeout( timeout );
			done();
		};

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

		// Simulate a cross-origin request.
		// Full cross-origin verification is only done when tests run from localhost,
		// e.g. when run via Karma (as we can depend on localhost resolving to 127.0.0.1).
		// In other cases we only do a more limited check: that the Origin header is sent.
		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() {

Review comment (suggestion):
The first line is quite long, please break it into two. Also, I'd mention that we explicitly want to run it in Karma:
```suggestion
	// We need to simulate cross-domain requests with the feature that
	// both 127.0.0.1 and localhost point to the mock http server.
 	// Skip the the test if we are not in localhost but make sure we run
 	// it in Karma.
```

Code after:
				success: function( data ) {
					assert.strictEqual( data, "test%5Blength%5D=7&test%5Bfoo%5D=bar", "Check if a sub-object with a length param is serialized correctly" );
				}
			} )
		).always( done );
	} );

	QUnit.test( "jQuery.post( String, Hash, Function ) - simple with xml", function( assert ) {
		assert.expect( 4 );
		var done = assert.async();

		jQuery.when(
			jQuery.post(
				url( "mock.php?action=xml" ),
				{
					cal: "5-2"
				},
				function( xml ) {
					jQuery( "math", xml ).each( function() {
						assert.strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
						assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
					} );
				}
			),
			jQuery.post( url( "mock.php?action=xml&cal=5-2" ), {}, function( xml ) {
				jQuery( "math", xml ).each( function() {
					assert.strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
					assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
				} );
			} )
		).always( function() {
			done();
		} );
	} );

	QUnit.test( "jQuery[get|post]( options ) - simple with xml", function( assert ) {
		assert.expect( 2 );
		var done = assert.async();

		jQuery.when.apply( jQuery,
			jQuery.map( [ "get", "post" ], function( method ) {
				return jQuery[ method ]( {
					url: url( "mock.php?action=xml" ),
					data: {
						cal: "5-2"
					},
					success: function( xml ) {
						jQuery( "math", xml ).each( function() {
							assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
						} );
					}