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

Code before:
	jQuery( "#donor-input" )[ 0 ].click();
} );

QUnit.test( "originalEvent property for Chrome, Safari, Fx & Edge of 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( 4 );

	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 ) {
		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[ 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 ) {

		// e.g. $(elem).click(...).click();
		$elem[ name ]( function( event ) {
			assert.equal( event.type, name, "triggered " + name );
		} )[ name ]().off( name );
	} );
} );

Review comment (suggestion):
I don't recall the specifics, but it looks like we had that xml in the index.html to start. That said, I think it's safe to remove at the end of the test. Regardless, I agree that it should be moved to non-alias tests.


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

	// test that special handlers do not blow up with VML elements (#7071)
	jQuery( "<xml:namespace ns='urn:schemas-microsoft-com:vml' prefix='v' />" ).appendTo( "head" );
	jQuery( "<v:oval id='oval' style='width:100pt;height:75pt;' fillcolor='red'> </v:oval>" ).appendTo( "#form" );
	jQuery( "#oval" ).click().keydown();
} );

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 ) {

		// e.g. $(elem).click(...).click();
		$elem[ name ]( function( event ) {
			assert.equal( event.type, name, "triggered " + name );
		} )[ name ]().off( name );
	} );
} );

// These tests are unreliable in Firefox
if ( !( /firefox/i.test( window.navigator.userAgent ) ) ) {