Skip to content

Commit

Permalink
Merge pull request #926 from capricorn86/task/923-selector-attr=value…
Browse files Browse the repository at this point in the history
…-without-quotes-not-working-with-the-latest-version

#923@patch: Fixes issue where attribute selectors with an operator an…
  • Loading branch information
capricorn86 committed May 18, 2023
2 parents 1963c8e + b03f613 commit 2c62156
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/happy-dom/src/query-selector/SelectorParser.ts
Expand Up @@ -142,7 +142,7 @@ export default class SelectorParser {
operator: match[11] || null,
value: match[12],
modifier: null,
regExp: this.getAttributeRegExp({ operator: match[7], value: match[8] })
regExp: this.getAttributeRegExp({ operator: match[11], value: match[12] })
});
} else if (match[13] && match[14]) {
currentSelectorItem.pseudos = currentSelectorItem.pseudos || [];
Expand Down
13 changes: 13 additions & 0 deletions packages/happy-dom/test/query-selector/QuerySelector.test.ts
Expand Up @@ -473,6 +473,19 @@ describe('QuerySelector', () => {
expect(elements[4] === container.children[0].children[1].children[2]).toBe(true);
});

it('Returns all elements with an attribute value that begins with a specified value using "[class^=cl]".', () => {
const container = document.createElement('div');
container.innerHTML = QuerySelectorHTML;
const elements = container.querySelectorAll('[class^=cl]');

expect(elements.length).toBe(5);
expect(elements[0] === container.children[0]).toBe(true);
expect(elements[1] === container.children[0].children[1]).toBe(true);
expect(elements[2] === container.children[0].children[1].children[0]).toBe(true);
expect(elements[3] === container.children[0].children[1].children[1]).toBe(true);
expect(elements[4] === container.children[0].children[1].children[2]).toBe(true);
});

it('Returns all elements with an attribute value that ends with a specified value using "[class$="ss2"]".', () => {
const container = document.createElement('div');
container.innerHTML = QuerySelectorHTML;
Expand Down

0 comments on commit 2c62156

Please sign in to comment.