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

fix: [#1274] Fixes problem with query selectors not finding SVG eleme… #1275

Merged
merged 1 commit into from
Feb 25, 2024
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/SelectorItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class SelectorItem {

// Tag name match
if (this.tagName) {
if (this.tagName !== '*' && this.tagName !== element[PropertySymbol.tagName]) {
if (this.tagName !== '*' && this.tagName !== element[PropertySymbol.tagName].toUpperCase()) {
return null;
}
priorityWeight += 1;
Expand Down
21 changes: 21 additions & 0 deletions packages/happy-dom/test/query-selector/QuerySelector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,27 @@ describe('QuerySelector', () => {
expect(element2 === div.children[0]).toBe(true);
});

it('Returns SVG elements', () => {
document.body.innerHTML = `<svg width="3955.829" height="880" viewBox="0 0 3955.829 880" xmlns="http://www.w3.org/2000/svg" id="id_svg_model">
<g id="svgGroup" stroke-linecap="round" fill-rule="evenodd" font-size="9pt"
stroke="#000" stroke-width="0.25mm" fill="none" style="stroke:#000;stroke-width:0.25mm;fill:none"
>
<path d="M 0 0 L 0 880 L 1272.697 880 A 80 80 0 0 0 1350.647 817.996 L 1416.442 533.006 A 120 120 0 0 1 1533.367 440 L 1977.914 440 L 2422.462 440 A 120 120 0 0 1 2539.386 533.006
L 2605.182 817.996 A 80 80 0 0 0 2683.131 880 L 3955.829 880 L 3955.829 0"
vector-effect="non-scaling-stroke">
</path>
</g>
</svg>`;

const svg = document.querySelector('svg');
const path = document.querySelector('path');

expect(svg?.constructor.name).toBe('SVGSVGElement');

// TODO: Should be SVGPathElement, but it is not supported yet
expect(path?.constructor.name).toBe('SVGElement');
});

it('Throws an error when providing an invalid selector', () => {
const div = document.createElement('div');
expect(() => div.querySelector('1')).toThrowError(
Expand Down
Loading