Debian Codegraph @

test/tests/unit/__queryEltAndDescendants.js

raw symbols SCIP
1 describe('__queryEltAndDescendants unit tests', function() {
2
3 it('returns descendants matching selector', function () {
4 let div = createProcessedHTML('<div><span class="foo"></span><span class="bar"></span></div>')
5 let results = htmx.__queryEltAndDescendants(div, '.foo')
6 assert.equal(results.length, 1)
7 assert.equal(results[0].className, 'foo')
8 })
9
10 it('includes element itself when it matches', function () {
11 let div = createProcessedHTML('<div class="foo"><span class="foo"></span></div>')
12 let results = htmx.__queryEltAndDescendants(div, '.foo')
13 assert.equal(results.length, 2)
14 assert.equal(results[0], div)
15 assert.equal(results[1], div.querySelector('span'))
16 })
17
18 it('excludes element itself when it does not match', function () {
19 let div = createProcessedHTML('<div class="bar"><span class="foo"></span></div>')
20 let results = htmx.__queryEltAndDescendants(div, '.foo')
21 assert.equal(results.length, 1)
22 assert.equal(results[0], div.querySelector('span'))
23 })
24
25 it('returns empty array when no matches', function () {
26 let div = createProcessedHTML('<div class="bar"><span class="baz"></span></div>')
27 let results = htmx.__queryEltAndDescendants(div, '.foo')
28 assert.equal(results.length, 0)
29 })
30
31 it('handles multiple matching descendants', function () {
32 let div = createProcessedHTML('<div><span class="foo"></span><span class="foo"></span><span class="foo"></span></div>')
33 let results = htmx.__queryEltAndDescendants(div, '.foo')
34 assert.equal(results.length, 3)
35 })
36
37 it('places element first when it matches', function () {
38 let div = createProcessedHTML('<div class="foo"><span class="foo"></span><p class="foo"></p></div>')
39 let results = htmx.__queryEltAndDescendants(div, '.foo')
40 assert.equal(results.length, 3)
41 assert.equal(results[0], div)
42 })
43
44 it('works with tag selectors', function () {
45 let div = createProcessedHTML('<div><span></span><span></span></div>')
46 let results = htmx.__queryEltAndDescendants(div, 'span')
47 assert.equal(results.length, 2)
48 })
49
50 it('works with attribute selectors', function () {
51 let div = createProcessedHTML('<div data-test="1"><span data-test="2"></span></div>')
52 let results = htmx.__queryEltAndDescendants(div, '[data-test]')
53 assert.equal(results.length, 2)
54 assert.equal(results[0], div)
55 })
56
57 });