4 <script src=
"../../resources/js-test.js"></script>
7 testRunner
.dumpAsText();
15 <ancestor id=
"doe" name=
"young" class=
"classic">
16 <target id=
"anotherTarget"></target>
19 <ancestor id=
"john" name=
"old" class=
"classic">
20 <sibling id=
"sibling"></sibling>
21 <target id=
"theTarget" webkit=
"fast"></target>
32 <lemon id=
"sour"></lemon>
43 description('This test makes sure the closest() API works correctly');
45 var theTarget
= document
.getElementById('theTarget');
46 var ancestor
= document
.getElementById('john');
47 var sour
= document
.getElementById('sour');
48 var sibling
= document
.getElementById('sibling');
49 var a
= document
.getElementById('a');
50 var b
= document
.getElementById('b');
51 var c
= document
.getElementById('c');
52 var d
= document
.getElementById('d');
53 var e
= document
.getElementById('e');
55 shouldBe('theTarget.closest("#theTarget")', 'theTarget');
56 shouldBe('theTarget.closest("ancestor")', 'ancestor');
57 shouldBe('theTarget.closest("tribe ancestor")', 'ancestor');
58 shouldBe('theTarget.closest("tribe > ancestor")', 'ancestor');
59 shouldBe('theTarget.closest("realm + ancestor")', 'ancestor');
60 shouldBe('theTarget.closest("realm ~ ancestor")', 'ancestor');
61 shouldBe('theTarget.closest("tribe, ancestor")', 'ancestor');
62 shouldBe('theTarget.closest("ancestor, tribe")', 'ancestor');
64 shouldBeNull('theTarget.closest("tribe realm")');
65 shouldBeNull('theTarget.closest("tribe realm throne")');
66 shouldBeNull('theTarget.closest("tribe realm ancestor")');
67 shouldBeNull('theTarget.closest("realm > ancestor")');
68 shouldBeNull('theTarget.closest("throne + ancestor")');
69 shouldBeNull('theTarget.closest("throne ~ ancestor")');
71 shouldBe('theTarget.closest(".classic")', 'ancestor');
72 shouldBe('theTarget.closest("#john")', 'ancestor');
73 shouldBeNull('theTarget.closest("doe")');
74 shouldBe('theTarget.closest("ancestor[name=old]")', 'ancestor');
75 shouldBeNull('theTarget.closest("ancestor[name=young]")');
77 shouldBeNull('theTarget.closest(null)');
78 shouldBeNull('theTarget.closest(undefined)');
80 shouldBe('sour.closest("lemon")', 'sour');
82 shouldBe('sour.closest("a, b, c, d, e")', 'e');
83 shouldBe('sour.closest("a, b, c")', 'c');
84 shouldBe('sour.closest("a, b")', 'b');
85 shouldBe('sour.closest("e, d, c, b, a")', 'e');
86 shouldBe('sour.closest("d, c, b, a")', 'd');
87 shouldBe('sour.closest("c, b, a")', 'c');
88 shouldBe('sour.closest("b, a")', 'b');
89 shouldBe('sour.closest("a")', 'a');
91 shouldBe('document.closest', 'undefined');
92 shouldThrow('document.closest()');
93 shouldThrow('theTarget.closest()');
94 shouldThrow('theTarget.closest("")');
95 shouldThrow('theTarget.closest(".123")');
96 shouldThrow('theTarget.closest(" ")');
97 shouldThrow('theTarget.closest(")")');
98 shouldThrow('theTarget.closest("(")');
99 shouldThrow('theTarget.closest("()")');
100 shouldThrow('theTarget.closest("^_^")');
101 shouldThrow('theTarget.closest("{")');
102 shouldThrow('theTarget.closest("}")');
103 shouldThrow('theTarget.closest("{}")');