|
2 | 2 | * Local DOM coverage not provided by our enabled WPT cases. |
3 | 3 | * These are independent tests, not adaptations of upstream WPT tests. |
4 | 4 | * Sibling traversal lives here while Node-properties.html requires unsupported |
5 | | - * HTML/XML document fixtures. Prefer WPT coverage when its dependencies are met. |
| 5 | + * HTML/XML document fixtures. Document-getElementById.html also needs parsed HTML. |
| 6 | + * Prefer WPT coverage when its dependencies are met. |
6 | 7 | */ |
7 | 8 | import { describe, expect, it } from 'vitest'; |
8 | 9 | import { Document } from '../src/dom.ts'; |
9 | 10 |
|
| 11 | +it('getElementById follows current tree order and ignores detached subtrees', () => { |
| 12 | + const document = new Document(() => {}); |
| 13 | + const first = document.createElement('div'); |
| 14 | + const nested = document.createElement('span'); |
| 15 | + const later = document.createElement('div'); |
| 16 | + nested.id = 'match'; |
| 17 | + later.id = 'match'; |
| 18 | + first.appendChild(nested); |
| 19 | + expect(document.getElementById('match')).toBeNull(); |
| 20 | + expect(document.getElementById('')).toBeNull(); |
| 21 | + |
| 22 | + document.documentElement.appendChild(first); |
| 23 | + document.documentElement.appendChild(later); |
| 24 | + expect(document.getElementById('match')).toBe(nested); |
| 25 | + |
| 26 | + document.documentElement.insertBefore(later, first); |
| 27 | + expect(document.getElementById('match')).toBe(later); |
| 28 | + later.remove(); |
| 29 | + expect(document.getElementById('match')).toBe(nested); |
| 30 | + |
| 31 | + nested.id = 'changed'; |
| 32 | + expect(document.getElementById('match')).toBeNull(); |
| 33 | + expect(document.getElementById('changed')).toBe(nested); |
| 34 | + first.remove(); |
| 35 | + expect(document.getElementById('changed')).toBeNull(); |
| 36 | +}); |
| 37 | + |
10 | 38 | describe('Node sibling properties outside WPT coverage', () => { |
11 | 39 | it.each(['createElement', 'createTextNode', 'createComment'] as const)( |
12 | 40 | '%s has no siblings when detached or an only child', |
|
0 commit comments