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

Code before:

testIframe(
	"css('width') should work correctly before document ready (trac-14084)",
	"css/cssWidthBeforeDocReady.html",
	function( assert, jQuery, window, document, cssWidthBeforeDocReady ) {
		assert.expect( 1 );
		assert.strictEqual( cssWidthBeforeDocReady, "100px", "elem.css('width') works correctly before document ready" );
	}
);

testIframe(
	"css('width') should work correctly with browser zooming",
	"css/cssWidthBrowserZoom.html",
	function( assert, jQuery, window, document, widthBeforeSet, widthAfterSet ) {
		assert.expect( 2 );
		assert.strictEqual( widthBeforeSet, "100px", "elem.css('width') works correctly with browser zoom" );
		assert.strictEqual( widthAfterSet, "100px", "elem.css('width', val) works correctly with browser zoom" );
	}
);

testIframe(
	"Test computeStyleTests for hidden iframe",
	"css/cssComputeStyleTests.html",
	function( assert, jQuery, window, document, initialHeight ) {
		assert.expect( 2 );
		assert.strictEqual( initialHeight, 0, "initial height should be undefined" );
		window.parent.jQuery( "#qunit-fixture-iframe" ).css( { "display": "block" } );
		jQuery( "#test" ).width( 600 );
		assert.strictEqual( jQuery( "#test" ).width(), 600, "width should be 600" );
	},
	undefined,
	{ "display": "none" }
);

( function() {
	var supportsFractionalGBCR,
		qunitFixture = document.getElementById( "qunit-fixture" ),
		div = document.createElement( "div" );
	div.style.width = "3.3px";
	qunitFixture.appendChild( div );
	supportsFractionalGBCR = div.getBoundingClientRect().width.toFixed( 1 ) === "3.3";
	qunitFixture.removeChild( div );

	QUnit.test( "css('width') and css('height') should return fractional values for nodes in the document", function( assert ) {
		if ( !supportsFractionalGBCR ) {
			assert.expect( 1 );
			assert.ok( true, "This browser doesn't support fractional values in getBoundingClientRect()" );
			return;
		}

		assert.expect( 2 );

Review comment (suggestion):
Looks like Safari actually is reporting offsetHeight for the div in the hidden iframe: https://github.com/jquery/jquery/actions/runs/6634909917/job/18189746921?pr=5317#step:9:161
```suggestion
		assert.strictEqual( initialHeight === 0 ? 20 : initialHeight, 20,
			"hidden-frame content sizes should be zero or accurate" );
```

Code after:

testIframe(
	"css('width') should work correctly before document ready (trac-14084)",
	"css/cssWidthBeforeDocReady.html",
	function( assert, jQuery, window, document, cssWidthBeforeDocReady ) {
		assert.expect( 1 );
		assert.strictEqual( cssWidthBeforeDocReady, "100px", "elem.css('width') works correctly before document ready" );
	}
);

testIframe(
	"css('width') should work correctly with browser zooming",
	"css/cssWidthBrowserZoom.html",
	function( assert, jQuery, window, document, widthBeforeSet, widthAfterSet ) {
		assert.expect( 2 );
		assert.strictEqual( widthBeforeSet, "100px", "elem.css('width') works correctly with browser zoom" );
		assert.strictEqual( widthAfterSet, "100px", "elem.css('width', val) works correctly with browser zoom" );
	}
);

testIframe(
	"Test computeStyleTests for hidden iframe",
	"css/cssComputeStyleTests.html",
	function( assert, jQuery, window, document, initialHeight ) {
		assert.expect( 2 );
		assert.strictEqual( initialHeight === 0 ? 20 : initialHeight, 20,
			"hidden-frame content sizes should be zero or accurate" );
		window.parent.jQuery( "#qunit-fixture-iframe" ).css( { "display": "block" } );
		jQuery( "#test" ).width( 600 );
		assert.strictEqual( jQuery( "#test" ).width(), 600, "width should be 600" );
	},
	undefined,
	{ "display": "none" }
);

( function() {
	var supportsFractionalGBCR,
		qunitFixture = document.getElementById( "qunit-fixture" ),
		div = document.createElement( "div" );
	div.style.width = "3.3px";
	qunitFixture.appendChild( div );
	supportsFractionalGBCR = div.getBoundingClientRect().width.toFixed( 1 ) === "3.3";
	qunitFixture.removeChild( div );

	QUnit.test( "css('width') and css('height') should return fractional values for nodes in the document", function( assert ) {
		if ( !supportsFractionalGBCR ) {
			assert.expect( 1 );
			assert.ok( true, "This browser doesn't support fractional values in getBoundingClientRect()" );
			return;
		}