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

QuerySelector returning incorrect results when using a grouped selector #1710

Closed
christiango opened this issue Jan 29, 2025 · 1 comment · Fixed by #1713
Closed

QuerySelector returning incorrect results when using a grouped selector #1710

christiango opened this issue Jan 29, 2025 · 1 comment · Fixed by #1713
Labels
bug Something isn't working

Comments

@christiango
Copy link
Contributor

Describe the bug
My team is trying to replace JSDOM with happy-dom and we are hitting some unexpected differences in behavior with regards to query selector. In particular, we have a minimal repro of a query selector that does not match the output of JSDOM or chromium.

To Reproduce
This unit test in QuerySelector.test.ts captures the issue.

	it('Supports grouped selectors', () => {
			const div = document.createElement('div');

			div.innerHTML = `
				<div class>
            		<h1><span>Here is a heading</span></h1>
            		<div class="a">
              			<span>With a child span</span>
            		</div>
          		</div>
			`;

			expect(div.querySelector('.a,h1')).toBe(div.children[0].children[0])
		})

Expected behavior
The behavior here is that the div with class a is being returned, instead of the h1 which is what is returned in jsdom and in the browser.

Screenshots
If applicable, add screenshots to help explain your problem.

Device:
Node 22 on Windows, MacOS, and Linux

Additional context

@christiango christiango added the bug Something isn't working label Jan 29, 2025
@christiango
Copy link
Contributor Author

Interestingly querySelectorAll returns the h1 as the first element. I'm going to debug this myself to see if I can track down a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant