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

Code before:

		display = $span.css( "display" );

		$span.hide();

		$span.fadeIn( 100, function() {
			assert.equal( $span.css( "display" ), display, "Expecting display: " + display );
			$span.fadeOut( 100, function() {
				assert.equal( $span.css( "display" ), displayNone, "Expecting display: " + displayNone );
				$span.fadeIn( 100, function() {
					assert.equal( $span.css( "display" ), display, "Expecting display: " + display );
				} );
			} );
		} );

		clock.tick( 300 );

		jQuery( "<div id='shadowHost'></div>" ).appendTo( "#qunit-fixture" );
		var shadowHost = document.querySelector( "#shadowHost" );
		var shadowRoot = shadowHost.attachShadow( { mode: "open" } );
		shadowRoot.innerHTML = "<style>.hidden{display: none;}</style>" +
			"<div id='shadowChild' class='hidden'></div>";
		var shadowChild = shadowRoot.querySelector( "#shadowChild" );

		var x = jQuery( shadowChild );
		x.fadeIn( 100, function() {
			assert.equal( x.css( "display" ), "block", "Expecting shadow display: " + "block" );
			x.fadeOut( 100, function() {
				assert.equal( x.css( "display" ), "none", "Expecting shadow display: " + "none" );
				x.fadeIn( 100, function() {
					assert.equal( x.css( "display" ), "block", "Expecting shadow display: " + "block" );
				} );
			} );
		} );

		clock.tick( 300 );

		assert.expectJqData( this, $span, "olddisplay" );
	} );
} );

QUnit.test( "animate(Hash, Object, Function)", function( assert ) {
	assert.expect( 1 );
	var hash = { opacity: "show" },
		hashCopy = jQuery.extend( {}, hash );
	jQuery( "#foo" ).animate( hash, 0, function() {
		assert.equal( hash.opacity, hashCopy.opacity, "Check if animate changed the hash parameter" );
	} );
} );

QUnit.test( "animate relative values", function( assert ) {

Review comment (refactor):
This whole block deserves its own test rather than being wedged into "Persist correct display value - {inline hidden,cascade hidden}", and I'd rather avoid using `fadeIn` etc. for tests that can be independent of them. Let's just simplify down to a verification that `toggle` works correctly with cascade-applied styles in shadow DOM.

Alternatively, we can switch some effects tests like this one from single-element to multi-element collections and make assertion across all of them (e.g., `$span = jQuery( "#show-tests span" )` → `$elems = jQuery( "#show-tests span" ).add( shadowChild )`, with corresponding consequences). But that seems like overkill.

Code after:

		display = $span.css( "display" );

		$span.hide();

		$span.fadeIn( 100, function() {
			assert.equal( $span.css( "display" ), display, "Expecting display: " + display );
			$span.fadeOut( 100, function() {
				assert.equal( $span.css( "display" ), displayNone, "Expecting display: " + displayNone );
				$span.fadeIn( 100, function() {
					assert.equal( $span.css( "display" ), display, "Expecting display: " + display );
				} );
			} );
		} );

		clock.tick( 300 );

		assert.expectJqData( this, $span, "olddisplay" );
	} );

	QUnit[ document.body.attachShadow ? "test" : "skip" ](
		"Persist correct display value - " + type + " hidden, shadow child", function( assert ) {
		assert.expect( 3 );

		jQuery( "<div id='shadowHost'></div>" ).appendTo( "#qunit-fixture" );

		var shadowHost = document.querySelector( "#shadowHost" );
		var shadowRoot = shadowHost.attachShadow( { mode: "open" } );
		shadowRoot.innerHTML = "<style>.hidden{display: none;}</style>" +
			"<span id='shadowChild' class='hidden'></span>";
		var shadowChild = shadowRoot.querySelector( "#shadowChild" );

		var $shadowChild = jQuery( shadowChild );
		var displayNone = "none";
		var display = "inline";
		var clock = this.clock;

		$shadowChild.fadeIn( 100, function() {
			assert.equal( $shadowChild.css( "display" ), display, "Expecting shadow display: " + display );
			$shadowChild.fadeOut( 100, function() {
				assert.equal( $shadowChild.css( "display" ), displayNone, "Expecting shadow display: " + displayNone );
				$shadowChild.fadeIn( 100, function() {
					assert.equal( $shadowChild.css( "display" ), display, "Expecting shadow display: " + display );
				} );
			} );
		} );

		clock.tick( 300 );

		assert.expectJqData( this, $shadowChild, "olddisplay" );
	} );