Skip to content

Commit

Permalink
Merge pull request #1275 from capricorn86/1274-error-in-v1350-with-ge…
Browse files Browse the repository at this point in the history
…t-svg-path-g-tag

fix: [#1274] Fixes problem with query selectors not finding SVG eleme…
  • Loading branch information
capricorn86 authored Feb 25, 2024
2 parents 0894067 + 1ff9de3 commit 8182be6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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

0 comments on commit 8182be6

Please sign in to comment.