Permalink
Browse files

add tests for closest with selector

  • Loading branch information...
mna committed Nov 11, 2012
1 parent 971be3c commit f98d0dce5076682d2041e58a232881025e8f9025
Showing with 35 additions and 2 deletions.
  1. +2 −2 testdata/page.html
  2. +33 −0 traversal_test.go
View
@@ -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">
@@ -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">
View
@@ -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.