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

Code before:
	jQuery( "#donor-input" ).on( "focus", function() {
		assert.ok( true, "got a focus event from the input" );
	} );
	jQuery( "#donor-input" ).trigger( "focus" );
} );


QUnit[ jQuery.fn.click ? "test" : "skip" ]( "trigger() shortcuts", function( assert ) {
	assert.expect( 5 );

	var counter, clickCounter,
		elem = jQuery( "<li><a href='#'>Change location</a></li>" ).prependTo( "#firstUL" );
	elem.find( "a" ).on( "click", function() {
		var close = jQuery( "spanx", this ); // same with jQuery(this).find("span");
		assert.equal( close.length, 0, "Context element does not exist, length must be zero" );
		assert.ok( !close[ 0 ], "Context element does not exist, direct access to element must return undefined" );
		return false;
	} ).click();

	// manually clean up detached elements
	elem.remove();

	jQuery( "#check1" ).click( function() {
		assert.ok( true, "click event handler for checkbox gets fired twice, see #815" );
	} ).click();

	counter = 0;
	jQuery( "#firstp" )[ 0 ].onclick = function() {
		counter++;
	};
	jQuery( "#firstp" ).click();
	assert.equal( counter, 1, "Check that click, triggers onclick event handler also" );

	clickCounter = 0;
	jQuery( "#simon1" )[ 0 ].onclick = function() {
		clickCounter++;
	};
	jQuery( "#simon1" ).click();
	assert.equal( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" );
} );

QUnit[ jQuery.fn.click ? "test" : "skip" ]( "Event aliases", function( assert ) {

	// Explicitly skipping focus/blur events due to their flakiness
	var	$elem = jQuery( "<div />" ).appendTo( "#qunit-fixture" ),
		aliases = ( "resize scroll click dblclick mousedown mouseup " +
			"mousemove mouseover mouseout mouseenter mouseleave change " +
			"select submit keydown keypress keyup contextmenu" ).split( " " );
	assert.expect( aliases.length );

	jQuery.each( aliases, function( i, name ) {

Review comment (suggestion):
mm, i test here that property is present with `focus` event which is already implemented in firefox :). Here i wanted to make sure event has always consistent set of properties


Code after:
			.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 );

		element.on( "focus", function( event ) {
			assert.notOk( event.isSimulated );
		} );

		element.trigger( "focus" );
	}
);

QUnit.test( "originalEvent property for Chrome, Safari, Fx & Edge of simulated event", function( assert ) {