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

Code before:
	"</div>";

	jQuery( "#qunit-fixture" ).append( html );

	jQuery( "#donor-outer" ).on( "focusin", function( event ) {
		assert.ok( true, "focusin bubbled to outer div" );
		assert.equal( event.originalEvent.type, "focus",
		             "make sure originalEvent type is correct" );
		assert.equal( event.type, "focusin", "make sure type is correct" );
	} );
	jQuery( "#donor-input" ).on( "focus", function() {
		assert.ok( true, "got a focus event from the input" );
	} );
	jQuery( "#donor-input" ).trigger( "focus" );
} );

QUnit.test(
	"navite stop(Immediate)Propagation methods should not be called from simulated event",
	function( assert ) {
		var userAgent = window.navigator.userAgent;

		if ( !( /firefox/i.test( userAgent ) || /safari/i.test( userAgent ) ) ) {
			assert.expect( 1 );
			assert.ok( true, "Assertions should run only in Chrome, Safari, Fx & Edge" );
			return;
		}

		assert.expect( 2 );

		var checker = {};

		var html = "<div id='donor-outer'>" +
			"<form id='donor-form'>" +
				"<input id='donor-input' type='radio' />" +
			"</form>" +
		"</div>";

		jQuery( "#qunit-fixture" ).append( html );

		jQuery( "#donor-outer" )
			.on( "focusin", function( event ) {
				checker.simple = sinon.stub( event.originalEvent, "stopPropagation" );
				event.stopPropagation();
			} )
			.on( "focusin", function( event ) {
				checker.immediate = sinon.stub( event.originalEvent, "stopImmediatePropagation" );
				event.stopImmediatePropagation();
			} );


		jQuery( "#donor-input" ).trigger( "focus" );

Review comment (suggestion):
> Input doesn't receive focus

It does receive focus, but not fully, it only represented with absent caret, it could happen when `stopPropagation` or `stopImmediatePropagation`, **not** `preventDefault` is called on original event, so here we test that it doesn't happen.

We can't actually trigger the real event, since it can be done only with e2e tests


Code after:
		var html = "<div id='donor-outer'>" +
			"<form id='donor-form'>" +
				"<input id='donor-input' type='radio' />" +
			"</form>" +
		"</div>";

		jQuery( "#qunit-fixture" ).append( html );
		var outer = jQuery( "#donor-outer" );

		outer
			.on( "focusin", function( event ) {
				checker.prevent = sinon.stub( event.originalEvent, "preventDefault" );
				event.preventDefault();
			} )
			.on( "focusin", function( event ) {
				checker.simple = sinon.stub( event.originalEvent, "stopPropagation" );
				event.stopPropagation();
			} )
			.on( "focusin", function( event ) {
				checker.immediate = sinon.stub( event.originalEvent, "stopImmediatePropagation" );
				event.stopImmediatePropagation();
			} );

		jQuery( "#donor-input" ).trigger( "focus" );
		assert.strictEqual( checker.simple.called, false );
		assert.strictEqual( checker.immediate.called, false );
		assert.strictEqual( checker.prevent.called, false );

		// We need to "off" it, since yes QUnit always update the fixtures
		// but "focus" event listener is attached to document for focus(in | out)
		// event and document doesn't get cleared obviously :)
		outer.off( "focusin" );
	}
);

QUnit.test(
	"isSimulated property always exist on event object",
	function( assert ) {
		var userAgent = window.navigator.userAgent;

		if ( !( /firefox/i.test( userAgent ) || /safari/i.test( userAgent ) ) ) {
			assert.expect( 1 );
			assert.ok( true, "Assertions should run only in Chrome, Safari, Fx & Edge" );
			return;
		}

		assert.expect( 1 );

		var element = jQuery( "<input/>" );

		jQuery( "#qunit-fixture" ).append( element );