Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#923@patch: Fixes issue where attribute selectors with an operator an… #926

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/happy-dom/src/query-selector/SelectorParser.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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