Permalink
Browse files

Offset: add tests for hidden elements + scroll

- Also add comments to hidden/disconnected tests noting
  this is to ensure consistency between branches
  • Loading branch information...
timmywil committed Jun 16, 2015
1 parent 0e4477c commit b04124222395a05c80d4f1c3a70333fdb07bfe3d
Showing with 15 additions and 1 deletion.
  1. +2 −0 test/data/offset/scroll.html
  2. +13 −1 test/unit/offset.js
@@ -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; }
</style>
<script src="../../jquery.js"></script>
@@ -32,6 +33,7 @@
<div id="scroll-1-1-1" class="scroll"></div>
</div>
</div>
<div id="hidden"></div>
<div id="forceScroll"></div>
<div id="marker"></div>
<p class="instructions">Click the white box to move the marker to it.</p>
View
@@ -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,14 +407,20 @@ 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" );
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()" );

0 comments on commit b041242

Please sign in to comment.