|
1 | | -describe('axe.utils.getAncestry', function () { |
| 1 | +describe('axe.utils.getAncestry', () => { |
2 | 2 | 'use strict'; |
3 | | - var fixture = document.getElementById('fixture'); |
4 | | - var shadowTest = axe.testUtils.shadowSupport.v1 ? it : xit; |
| 3 | + const fixture = document.getElementById('fixture'); |
5 | 4 |
|
6 | | - afterEach(function () { |
| 5 | + afterEach(() => { |
7 | 6 | fixture.innerHTML = ''; |
8 | 7 | }); |
9 | 8 |
|
10 | | - it('should be a function', function () { |
| 9 | + it('should be a function', () => { |
11 | 10 | assert.isFunction(axe.utils.getAncestry); |
12 | 11 | }); |
13 | 12 |
|
14 | | - it('should generate an ancestry selector', function () { |
| 13 | + it('should generate an ancestry selector', () => { |
15 | 14 | fixture.innerHTML = '<div>1</div> <p>2</p> <p>3</p>'; |
16 | 15 |
|
17 | | - var sel1 = axe.utils.getAncestry(fixture.children[0]); |
| 16 | + const sel1 = axe.utils.getAncestry(fixture.children[0]); |
18 | 17 | assert.equal(sel1, 'html > body > div:nth-child(1) > div:nth-child(1)'); |
19 | 18 | assert.isNotNull(document.querySelector(sel1)); |
20 | 19 |
|
21 | | - var sel2 = axe.utils.getAncestry(fixture.children[1]); |
| 20 | + const sel2 = axe.utils.getAncestry(fixture.children[1]); |
22 | 21 | assert.equal(sel2, 'html > body > div:nth-child(1) > p:nth-child(2)'); |
23 | 22 | assert.isNotNull(document.querySelector(sel1)); |
24 | 23 |
|
25 | | - var sel3 = axe.utils.getAncestry(fixture.children[2]); |
| 24 | + const sel3 = axe.utils.getAncestry(fixture.children[2]); |
26 | 25 | assert.equal(sel3, 'html > body > div:nth-child(1) > p:nth-child(3)'); |
27 | 26 | assert.isNotNull(document.querySelector(sel1)); |
28 | 27 | }); |
29 | 28 |
|
30 | | - shadowTest('generates selectors of nested shadow trees', function () { |
31 | | - var node = document.createElement('section'); |
| 29 | + it('generates selectors of nested shadow trees', () => { |
| 30 | + const node = document.createElement('section'); |
32 | 31 | fixture.appendChild(node); |
33 | 32 |
|
34 | | - var shadowRoot1 = node.attachShadow({ mode: 'open' }); |
| 33 | + const shadowRoot1 = node.attachShadow({ mode: 'open' }); |
35 | 34 | shadowRoot1.innerHTML = '<div><article><slot /></article</div>'; |
36 | 35 |
|
37 | | - var shadowRoot2 = shadowRoot1 |
| 36 | + const shadowRoot2 = shadowRoot1 |
38 | 37 | .querySelector('article') |
39 | 38 | .attachShadow({ mode: 'open' }); |
40 | 39 | shadowRoot2.innerHTML = '<h1>Hello world</h1>'; |
41 | 40 |
|
42 | | - var target = shadowRoot2.querySelector('h1'); |
43 | | - var sel = axe.utils.getAncestry(target); |
| 41 | + const target = shadowRoot2.querySelector('h1'); |
| 42 | + const sel = axe.utils.getAncestry(target); |
44 | 43 | assert.deepEqual(sel, [ |
45 | 44 | 'html > body > div:nth-child(1) > section', |
46 | 45 | 'div > article', |
47 | 46 | 'h1' |
48 | 47 | ]); |
49 | 48 | }); |
| 49 | + |
| 50 | + it('generates selectors of siblings in shadow tree', () => { |
| 51 | + const node = document.createElement('section'); |
| 52 | + fixture.appendChild(node); |
| 53 | + |
| 54 | + const shadowRoot = node.attachShadow({ mode: 'open' }); |
| 55 | + shadowRoot.innerHTML = '<div>1</div> <div>2</div>'; |
| 56 | + |
| 57 | + const sel1 = axe.utils.getAncestry(shadowRoot.children[0]); |
| 58 | + assert.deepEqual(sel1, [ |
| 59 | + 'html > body > div:nth-child(1) > section', |
| 60 | + 'div:nth-child(1)' |
| 61 | + ]); |
| 62 | + |
| 63 | + const sel2 = axe.utils.getAncestry(shadowRoot.children[1]); |
| 64 | + assert.deepEqual(sel2, [ |
| 65 | + 'html > body > div:nth-child(1) > section', |
| 66 | + 'div:nth-child(2)' |
| 67 | + ]); |
| 68 | + }); |
50 | 69 | }); |
0 commit comments