From: Timmy Willison Date: Tue, 16 Jun 2015 17:24:12 +0000 (-0400) Subject: Offset: add tests for hidden elements + scroll X-Git-Tag: 3.0.0-alpha1~19 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b04124222395a05c80d4f1c3a70333fdb07bfe3d;p=jquery.git Offset: add tests for hidden elements + scroll - Also add comments to hidden/disconnected tests noting this is to ensure consistency between branches --- diff --git a/test/data/offset/scroll.html b/test/data/offset/scroll.html index 113400ce4..ad35ab84a 100644 --- a/test/data/offset/scroll.html +++ b/test/data/offset/scroll.html @@ -11,6 +11,7 @@ #scroll-1-1 { top: 1px; left: 1px; } #scroll-1-1-1 { top: 1px; left: 1px; } #forceScroll { width: 5000px; height: 5000px; } + #hidden { display: none; } #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } @@ -32,6 +33,7 @@
+

Click the white box to move the marker to it.

diff --git a/test/unit/offset.js b/test/unit/offset.js index bffe87dd1..65243387f 100644 --- a/test/unit/offset.js +++ b/test/unit/offset.js @@ -52,6 +52,9 @@ test("disconnected element", function() { var result = jQuery( document.createElement( "div" ) ).offset(); + // These tests are solely for master/compat consistency + // Retrieving offset on disconnected/hidden elements is not officially + // valid input, but will return zeros for back-compat equal( result.top, 0, "Retrieving offset on disconnected elements returns zeros (gh-2310)" ); equal( result.left, 0, "Retrieving offset on disconnected elements returns zeros (gh-2310)" ); }); @@ -64,6 +67,9 @@ test("hidden (display: none) element", function() { node.remove(); + // These tests are solely for master/compat consistency + // Retrieving offset on disconnected/hidden elements is not officially + // valid input, but will return zeros for back-compat equal( result.top, 0, "Retrieving offset on hidden elements returns zeros (gh-2310)" ); equal( result.left, 0, "Retrieving offset on hidden elements returns zeros (gh-2310)" ); }); @@ -401,7 +407,7 @@ testIframe("offset/table", "table", function( $ ) { }); testIframe("offset/scroll", "scroll", function( $, win ) { - expect(28); + expect( 30 ); equal( $("#scroll-1").offset().top, 7, "jQuery('#scroll-1').offset().top" ); equal( $("#scroll-1").offset().left, 7, "jQuery('#scroll-1').offset().left" ); @@ -409,6 +415,12 @@ testIframe("offset/scroll", "scroll", function( $, win ) { equal( $("#scroll-1-1").offset().top, 11, "jQuery('#scroll-1-1').offset().top" ); equal( $("#scroll-1-1").offset().left, 11, "jQuery('#scroll-1-1').offset().left" ); + // These tests are solely for master/compat consistency + // Retrieving offset on disconnected/hidden elements is not officially + // valid input, but will return zeros for back-compat + equal( $("#hidden").offset().top, 0, "Hidden elements do not subtract scroll" ); + equal( $("#hidden").offset().left, 0, "Hidden elements do not subtract scroll" ); + // scroll offset tests .scrollTop/Left equal( $("#scroll-1").scrollTop(), 5, "jQuery('#scroll-1').scrollTop()" ); equal( $("#scroll-1").scrollLeft(), 5, "jQuery('#scroll-1').scrollLeft()" );