Skip to content

Commit

Permalink
Offset: add tests for hidden elements + scroll
Browse files Browse the repository at this point in the history
- 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 b041242
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions test/data/offset/scroll.html
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
14 changes: 13 additions & 1 deletion test/unit/offset.js
Expand Up @@ -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)" );
});
Expand All @@ -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)" );
});
Expand Down Expand Up @@ -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()" );
Expand Down

0 comments on commit b041242

Please sign in to comment.