From 182caf77e3cd54f2abef01a9ecd2ab9c6384492b Mon Sep 17 00:00:00 2001 From: chocolateboy Date: Wed, 18 Dec 2024 13:08:46 +0000 Subject: [PATCH 1/3] fix: Remove redundant querySelector type check Remove type check which is covered by (and shadows) subsequent checks --- packages/happy-dom/src/query-selector/QuerySelector.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/happy-dom/src/query-selector/QuerySelector.ts b/packages/happy-dom/src/query-selector/QuerySelector.ts index 6b0d00a0f..2c2504b6b 100644 --- a/packages/happy-dom/src/query-selector/QuerySelector.ts +++ b/packages/happy-dom/src/query-selector/QuerySelector.ts @@ -205,12 +205,6 @@ export default class QuerySelector { ); } - if (typeof selector === 'function' || typeof selector === 'symbol') { - throw new window.DOMException( - `Failed to execute 'querySelector' on '${node.constructor.name}': '${selector}' is not a valid selector.` - ); - } - if (typeof selector === 'function') { throw new window.DOMException( `Failed to execute 'querySelector' on '${node.constructor.name}': '${selector}' is not a valid selector.` From 86286172790f54959cc5440c7b0b4efdb43a86e0 Mon Sep 17 00:00:00 2001 From: chocolateboy Date: Mon, 30 Dec 2024 20:53:39 +0000 Subject: [PATCH 2/3] fix: Update error message to include node type as per other checks --- packages/happy-dom/src/query-selector/QuerySelector.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/happy-dom/src/query-selector/QuerySelector.ts b/packages/happy-dom/src/query-selector/QuerySelector.ts index 2c2504b6b..a6d428750 100644 --- a/packages/happy-dom/src/query-selector/QuerySelector.ts +++ b/packages/happy-dom/src/query-selector/QuerySelector.ts @@ -92,7 +92,9 @@ export default class QuerySelector { } if (typeof selector === 'symbol') { - throw new window.TypeError(`Cannot convert a Symbol value to a string`); + throw new window.TypeError( + `Failed to execute 'querySelectorAll' on '${node.constructor.name}': Cannot convert a Symbol value to a string` + ); } selector = String(selector); @@ -212,7 +214,9 @@ export default class QuerySelector { } if (typeof selector === 'symbol') { - throw new window.TypeError(`Cannot convert a Symbol value to a string`); + throw new window.TypeError( + `Failed to execute 'querySelector' on '${node.constructor.name}': Cannot convert a Symbol value to a string` + ); } selector = String(selector); From 9c5f61cf8c6be77ddcfcfa34b8db5df075ea1f7e Mon Sep 17 00:00:00 2001 From: chocolateboy Date: Mon, 30 Dec 2024 21:21:07 +0000 Subject: [PATCH 3/3] fix: Update tests to include node type --- .../happy-dom/test/query-selector/QuerySelector.test.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/happy-dom/test/query-selector/QuerySelector.test.ts b/packages/happy-dom/test/query-selector/QuerySelector.test.ts index e89dbec51..51ee30247 100644 --- a/packages/happy-dom/test/query-selector/QuerySelector.test.ts +++ b/packages/happy-dom/test/query-selector/QuerySelector.test.ts @@ -34,7 +34,9 @@ describe('QuerySelector', () => { ) ); expect(() => container.querySelectorAll((Symbol('test')))).toThrow( - new Error(`Cannot convert a Symbol value to a string`) + new TypeError( + `Failed to execute 'querySelectorAll' on 'HTMLDivElement': Cannot convert a Symbol value to a string` + ) ); expect(() => container.querySelectorAll((true))).not.toThrow(); }); @@ -1225,7 +1227,9 @@ describe('QuerySelector', () => { ) ); expect(() => container.querySelector((Symbol('test')))).toThrow( - new Error(`Cannot convert a Symbol value to a string`) + new TypeError( + `Failed to execute 'querySelector' on 'HTMLDivElement': Cannot convert a Symbol value to a string` + ) ); expect(() => container.querySelector((true))).not.toThrow(); });