Skip to content

Commit

Permalink
Merge pull request #797 from btea/task/642-selector-judgment
Browse files Browse the repository at this point in the history
#642@patch: Handle selector special value.
  • Loading branch information
capricorn86 committed Apr 4, 2023
2 parents 0b5760b + 58c4e0c commit f75f5e2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/happy-dom/src/query-selector/QuerySelector.ts
Expand Up @@ -24,6 +24,14 @@ export default class QuerySelector {
public static querySelectorAll(node: INode, selector: string): INodeList<IElement> {
const matches = new NodeList<IElement>();

if (selector === '') {
throw new Error(
"Failed to execute 'querySelectorAll' on 'Element': The provided selector is empty."
);
}
if (selector === null || selector === undefined) {
return matches;
}
for (const parts of this.getSelectorParts(selector)) {
for (const element of this.findAll(node, [node], parts)) {
if (!matches.includes(element)) {
Expand All @@ -43,6 +51,14 @@ export default class QuerySelector {
* @returns HTML element.
*/
public static querySelector(node: INode, selector: string): IElement {
if (selector === '') {
throw new Error(
"Failed to execute 'querySelector' on 'Element': The provided selector is empty."
);
}
if (selector === null || selector === undefined) {
return null;
}
for (const parts of this.getSelectorParts(selector)) {
const match = this.findFirst(node, [node], parts);

Expand Down

0 comments on commit f75f5e2

Please sign in to comment.