Skip to content

Commit

Permalink
fix: [#1352] Fixes problem when the error for the selector :is and :w…
Browse files Browse the repository at this point in the history
…here without argument was not handled correctly
  • Loading branch information
capricorn86 committed Mar 26, 2024
1 parent ee51a80 commit d07d165
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/happy-dom/src/query-selector/SelectorItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ export default class SelectorItem {
case 'nth-of-type':
case 'nth-last-child':
case 'nth-last-of-type':
case 'is':
case 'where':
if (!pseudo.arguments) {
if (this.ignoreErrors) {
return null;
Expand Down
8 changes: 8 additions & 0 deletions packages/happy-dom/test/query-selector/QuerySelector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,12 @@ describe('QuerySelector', () => {
expect(() => element.matches(':not')).toThrow(
new Error(`Failed to execute 'matches' on 'HTMLElement': ':not' is not a valid selector.`)
);
expect(() => element.matches(':is')).toThrow(
new Error(`Failed to execute 'matches' on 'HTMLElement': ':is' is not a valid selector.`)
);
expect(() => element.matches(':where')).toThrow(
new Error(`Failed to execute 'matches' on 'HTMLElement': ':where' is not a valid selector.`)
);
expect(() => element.matches('div:not')).toThrow(
new Error(
`Failed to execute 'matches' on 'HTMLElement': 'div:not' is not a valid selector.`
Expand All @@ -1389,6 +1395,8 @@ describe('QuerySelector', () => {
const element = div.children[0];
expect(QuerySelector.matches(element, '1', { ignoreErrors: true })).toBe(null);
expect(QuerySelector.matches(element, ':not', { ignoreErrors: true })).toBe(null);
expect(QuerySelector.matches(element, ':is', { ignoreErrors: true })).toBe(null);
expect(QuerySelector.matches(element, ':where', { ignoreErrors: true })).toBe(null);
expect(QuerySelector.matches(element, 'div:not', { ignoreErrors: true })).toBe(null);
});
});
Expand Down

0 comments on commit d07d165

Please sign in to comment.