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

Code before:
	// based on matching done in wrapMap which should be ignored.
	var elem = jQuery( "<td></td></tr></tbody></table><td></td>" );
	assert.strictEqual( elem.length, 2, "Two elements created" );
	assert.strictEqual( elem[ 0 ].nodeName.toLowerCase(), "td", "First element is td" );
	assert.strictEqual( elem[ 1 ].nodeName.toLowerCase(), "td", "Second element is td" );
} );

// Test trustedTypes support in browsers where they're supported (currently Chrome 83+).
// Browsers with no TrustedHTML support still run tests on object wrappers with
// a proper `toString` function.
testIframe(
	"Basic TrustedHTML support (gh-4409)",
	"mock.php?action=trustedHtml",
	function( assert, jQuery, window, document, test ) {

		assert.expect( 5 );

		test.forEach( function( result ) {
			assert.deepEqual( result.actual, result.expected, result.message );
		} );
	}
);

// Custom event handler test case

QUnit.test( "should handle custom '_se-custom-destroy' event correctly", function( assert ) {

	// Define the expected number of assertions

	assert.expect( 4 );

	// Set up the HTML structure by appending to the existing fixture

	var fixture = jQuery( "#qunit-fixture" );

	fixture.append( `
	<div id="container">
	  <div class="guarded removeself" data-elt="one">
	    Guarded 1
	  </div>
	  <div class="guarded" data-elt="two">
	    Guarded 2
	  </div>
	  <div class="guarded" data-elt="three">
	    Guarded 3
	  </div>
	</div>
	` );

	// Define the custom event handler
	jQuery.event.special[ "_se-custom-destroy" ] = {

Review comment (suggestion):
This is not about any specific event; also, this wording doesn't follow the style from other tests. How about:
```suggestion
QUnit.test( "Cleans data for events removing elements on `remove` (gh-5214)", function( assert ) {
```
Maybe others have a better suggestion for a more succinct name.

Code after:
	// based on matching done in wrapMap which should be ignored.
	var elem = jQuery( "<td></td></tr></tbody></table><td></td>" );
	assert.strictEqual( elem.length, 2, "Two elements created" );
	assert.strictEqual( elem[ 0 ].nodeName.toLowerCase(), "td", "First element is td" );
	assert.strictEqual( elem[ 1 ].nodeName.toLowerCase(), "td", "Second element is td" );
} );

// Test trustedTypes support in browsers where they're supported (currently Chrome 83+).
// Browsers with no TrustedHTML support still run tests on object wrappers with
// a proper `toString` function.
testIframe(
	"Basic TrustedHTML support (gh-4409)",
	"mock.php?action=trustedHtml",
	function( assert, jQuery, window, document, test ) {

		assert.expect( 5 );

		test.forEach( function( result ) {
			assert.deepEqual( result.actual, result.expected, result.message );
		} );
	}
);

QUnit.test( "should handle node removal in event's remove hook (gh-5214)", function( assert ) {

	assert.expect( 4 );

	jQuery(
		"<div id='container'>" +
		"	<div class='guarded removeself' data-elt='one'>" +
		"		Guarded 1" +
		"	</div>" +
		"	<div class='guarded' data-elt='two'>" +
		"		Guarded 2" +
		"	</div>" +
		"	<div class='guarded' data-elt='three'>" +
		"		Guarded 3" +
		"	</div>" +
		"</div>"
	).appendTo( "#qunit-fixture" );

	// Define the custom event handler
	jQuery.event.special.removeondestroy = {
		remove: function( ) {
			var $t = jQuery( this );
			assert.step( $t.data( "elt" ) );
			if ( $t.is( ".removeself" ) ) {
				$t.remove();
			}
		}
	};