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

Code before:
	ajaxTest( "jQuery.ajax() - dataType html", 5, function( assert ) {
		return {
			setup: function() {
				Globals.register( "testFoo" );
				Globals.register( "testBar" );
			},
			dataType: "html",
			url: url( "mock.php?action=testHTML&baseURL=" + baseURL ),
			success: function( data ) {
				assert.ok( data.match( /^html text/ ), "Check content for datatype html" );
				jQuery( "#ap" ).html( data );
				assert.strictEqual( window[ "testFoo" ], "foo", "Check if script was evaluated for datatype html" );
				assert.strictEqual( window[ "testBar" ], "bar", "Check if script src was evaluated for datatype html" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - do execute scripts if JSONP from unsuccessful responses", 1, function( assert ) {
		var testMsg = "Unsuccessful JSONP requests should have a JSON body";
		return {
			dataType: "jsonp",
			url: url( "mock.php?action=errorWithScript" ),
			// error is the significant assertion
			error: function( xhr ) {
				var expected = { "status": 404, "msg": "Not Found" };
				assert.equal( xhr.responseJSON, expected, testMsg );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - do not execute scripts from unsuccessful responses (gh-4250)", 11, function( assert ) {
		var globalEval = jQuery.globalEval;

		var failConverters = {
			"text script": function() {
				assert.ok( false, "No converter for unsuccessful response" );
			}
		};

		function request( title, options ) {
			var testMsg = title + ": expected file missing status";
			return jQuery.extend( {
				beforeSend: function() {
					jQuery.globalEval = function() {
						assert.ok( false, "Should not eval" );
					};
				},
				complete: function() {
					jQuery.globalEval = globalEval;
				},
				// error is the significant assertion

Review comment (refactor):
`equal` just does an abstract equality comparison, you want `deepEqual` here. See https://api.qunitjs.com/assert/equal/ & https://api.qunitjs.com/assert/deepEqual/.

Code after:
	ajaxTest( "jQuery.ajax() - dataType html", 5, function( assert ) {
		return {
			setup: function() {
				Globals.register( "testFoo" );
				Globals.register( "testBar" );
			},
			dataType: "html",
			url: url( "mock.php?action=testHTML&baseURL=" + baseURL ),
			success: function( data ) {
				assert.ok( data.match( /^html text/ ), "Check content for datatype html" );
				jQuery( "#ap" ).html( data );
				assert.strictEqual( window[ "testFoo" ], "foo", "Check if script was evaluated for datatype html" );
				assert.strictEqual( window[ "testBar" ], "bar", "Check if script src was evaluated for datatype html" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - do execute scripts if JSONP from unsuccessful responses", 1, function( assert ) {
		var testMsg = "Unsuccessful JSONP requests should have a JSON body";
		return {
			dataType: "jsonp",
			url: url( "mock.php?action=errorWithScript" ),
			// error is the significant assertion
			error: function( xhr ) {
				var expected = { "status": 404, "msg": "Not Found" };
				assert.deepEqual( xhr.responseJSON, expected, testMsg );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - do not execute scripts from unsuccessful responses (gh-4250)", 11, function( assert ) {
		var globalEval = jQuery.globalEval;

		var failConverters = {
			"text script": function() {
				assert.ok( false, "No converter for unsuccessful response" );
			}
		};

		function request( title, options ) {
			var testMsg = title + ": expected file missing status";
			return jQuery.extend( {
				beforeSend: function() {
					jQuery.globalEval = function() {
						assert.ok( false, "Should not eval" );
					};
				},
				complete: function() {
					jQuery.globalEval = globalEval;
				},
				// error is the significant assertion