Commit 6a871de7 authored by David Sveningsson's avatar David Sveningsson
Browse files

fix(dom): `querySelector` and friends return empty when selector is empty

parent a4f90541
......@@ -609,6 +609,11 @@ describe("HtmlElement", () => {
const el = root.querySelector("foobar");
expect(el).toBeNull();
});
it("should return null if selector is empty", () => {
const el = root.querySelector("");
expect(el).toBeNull();
});
});
describe("querySelectorAll()", () => {
......@@ -636,6 +641,11 @@ describe("HtmlElement", () => {
const el = root.querySelectorAll("missing");
expect(el).toEqual([]);
});
it("should return [] if selector is empty", () => {
const el = root.querySelectorAll("");
expect(el).toEqual([]);
});
});
describe("visitDepthFirst()", () => {
......
......@@ -426,6 +426,9 @@ export class HtmlElement extends DOMNode {
private *querySelectorImpl(
selectorList: string
): IterableIterator<HtmlElement> {
if (!selectorList) {
return;
}
for (const selector of selectorList.split(/,\s*/)) {
const pattern = new Selector(selector);
yield* pattern.match(this);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment