Skip to content

Commit

Permalink
#928@patch: Fixes problem with querySelectorAll() not always retirnin…
Browse files Browse the repository at this point in the history
…g elements in document order.
  • Loading branch information
capricorn86 committed May 22, 2023
1 parent cbdca8b commit 19d540c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/happy-dom/src/query-selector/QuerySelector.ts
Expand Up @@ -221,7 +221,7 @@ export default class QuerySelector {

for (let i = 0, max = children.length; i < max; i++) {
const child = children[i];
const position = (documentPosition ? documentPosition + '>' : '') + i;
const position = (documentPosition ? documentPosition + '>' : '') + String.fromCharCode(i);

if (selectorItem.match(child)) {
if (!nextSelectorItem) {
Expand Down
23 changes: 23 additions & 0 deletions packages/happy-dom/test/query-selector/QuerySelector.test.ts
Expand Up @@ -128,6 +128,29 @@ describe('QuerySelector', () => {
'ccb',
'ccc'
]);

element.innerHTML = `
<div>0</div>
<button>1</button>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<button>8</button>
<button>9</button>
<button>10</button>
<button>11</button>
`;

expect(Array.from(element.querySelectorAll('button')).map((div) => div.textContent)).toEqual([
'1',
'8',
'9',
'10',
'11'
]);
});

it('Returns a NodeList with the method item().', () => {
Expand Down

0 comments on commit 19d540c

Please sign in to comment.