Skip to content

Commit

Permalink
add tests for closest with selector
Browse files Browse the repository at this point in the history
  • Loading branch information
mna committed Nov 11, 2012
1 parent 971be3c commit f98d0dc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions testdata/page.html
Expand Up @@ -19,7 +19,7 @@
<div class="pvk-gutter">
&nbsp;
</div>
<div class="pvk-content">
<div class="pvk-content" id="pc1">
<div ng-controller="HeroCtrl" class="hero-unit">
<div class="container-fluid" id="cf2">
<div class="row-fluid" id="cf2-1">
Expand Down Expand Up @@ -54,7 +54,7 @@ <h1>
<div class="pvk-gutter">
&nbsp;
</div>
<div class="pvk-content">
<div class="pvk-content" id="pc2">
<div class="container-fluid" id="cf3">
<div class="row-fluid">
<div ng-cloak="" view-on-display="" ng-controller="MsgCtrl" ng-class="{'displayed': blockIsDisplayed}" class="message-box">
Expand Down
33 changes: 33 additions & 0 deletions traversal_test.go
Expand Up @@ -576,3 +576,36 @@ func TestPrevFilteredUntilNodesRollback(t *testing.T) {
sel3 := sel.PrevFilteredUntilNodes(".odd", sel2.Nodes...).End()
AssertEqual(t, sel, sel3)
}

func TestClosestItself(t *testing.T) {
sel := Doc2().Find(".three")
sel2 := sel.Closest(".row")
AssertLength(t, sel2.Nodes, sel.Length())
AssertSelectionIs(t, sel2, "#n3", "#nf3")
}

func TestClosestNoDupes(t *testing.T) {
sel := Doc().Find(".span12")
sel2 := sel.Closest(".pvk-content")
AssertLength(t, sel2.Nodes, 1)
AssertClass(t, sel2, "pvk-content")
}

func TestClosestNone(t *testing.T) {
sel := Doc().Find("h4")
sel2 := sel.Closest("a")
AssertLength(t, sel2.Nodes, 0)
}

func TestClosestMany(t *testing.T) {
sel := Doc().Find(".container-fluid")
sel2 := sel.Closest(".pvk-content")
AssertLength(t, sel2.Nodes, 2)
AssertSelectionIs(t, sel2, "#pc1", "#pc2")
}

func TestClosestRollback(t *testing.T) {
sel := Doc().Find(".container-fluid")
sel2 := sel.Closest(".pvk-content").End()
AssertEqual(t, sel, sel2)
}

0 comments on commit f98d0dc

Please sign in to comment.