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

Code before:
		}

		assert.strictEqual( exceptionCaught, undefined,
			"Preventing default on focusin throws no exception" );

		done();
		done = null;
	} );
	input.trigger( "focus" );

	// DOM focus is unreliable in TestSwarm; set a simulated event workaround timeout
	setTimeout( function() {
		if ( !done ) {
			return;
		}
		input[ 0 ].addEventListener( "click", function( nativeEvent ) {
			jQuery.event.simulate( "focusin", this, jQuery.event.fix( nativeEvent ) );
		} );
		input[ 0 ].click();
	}, QUnit.config.testTimeout / 4 || 1000 );
} );

QUnit.test( ".on('focus', fn) on a text node doesn't throw", function( assert ) {
	assert.expect( 1 );

	jQuery( "<div></div>text<span></span>" )
		.on( "focus", function() {} );

	assert.ok( true, "No crash" );
} );

QUnit.test( "Donor event interference", function( assert ) {
	assert.expect( 8 );

	var outer = jQuery(
			"<div id='donor-outer'>" +
				"<form id='donor-form'>" +
					"<input id='donor-input' type='checkbox' />" +
				"</form>" +
			"</div>"
		).appendTo( "#qunit-fixture" ),
		input = jQuery( "#donor-input" );

	input.on( "click", function( event ) {
		assert.equal( event.type, "click", "click event at input" );
		assert.ok( !event.isPropagationStopped(), "click event at input is still propagating" );
		assert.equal( typeof event.originalEvent, "object",
			"click event at input has originalEvent property" );
	} );
	outer.on( "click", function( event ) {
		assert.equal( event.type, "click", "click event at ancestor" );

Review comment (suggestion):
I'd prefer something more obvious here such as `jQuery( document.createTextNode("text") )`, but this works as long as the behavior doesn't change (do we test that, though?).

Code after:
		}

		assert.strictEqual( exceptionCaught, undefined,
			"Preventing default on focusin throws no exception" );

		done();
		done = null;
	} );
	input.trigger( "focus" );

	// DOM focus is unreliable in TestSwarm; set a simulated event workaround timeout
	setTimeout( function() {
		if ( !done ) {
			return;
		}
		input[ 0 ].addEventListener( "click", function( nativeEvent ) {
			jQuery.event.simulate( "focusin", this, jQuery.event.fix( nativeEvent ) );
		} );
		input[ 0 ].click();
	}, QUnit.config.testTimeout / 4 || 1000 );
} );

QUnit.test( ".on('focus', fn) on a text node doesn't throw", function( assert ) {
	assert.expect( 1 );

	jQuery( document.createTextNode( "text" ) )
		.on( "focus", function() {} );

	assert.ok( true, "No crash" );
} );

QUnit.test( "Donor event interference", function( assert ) {
	assert.expect( 8 );

	var outer = jQuery(
			"<div id='donor-outer'>" +
				"<form id='donor-form'>" +
					"<input id='donor-input' type='checkbox' />" +
				"</form>" +
			"</div>"
		).appendTo( "#qunit-fixture" ),
		input = jQuery( "#donor-input" );

	input.on( "click", function( event ) {
		assert.equal( event.type, "click", "click event at input" );
		assert.ok( !event.isPropagationStopped(), "click event at input is still propagating" );
		assert.equal( typeof event.originalEvent, "object",
			"click event at input has originalEvent property" );
	} );
	outer.on( "click", function( event ) {
		assert.equal( event.type, "click", "click event at ancestor" );