From 06115f715c01e70747f764af87c1a7c669016325 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Mon, 22 Apr 2024 11:26:55 +0800 Subject: [PATCH 1/5] feat: [#1411] Add queryCommandSupported method. --- packages/happy-dom/src/nodes/document/Document.ts | 12 ++++++++++++ .../happy-dom/test/nodes/document/Document.test.ts | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/packages/happy-dom/src/nodes/document/Document.ts b/packages/happy-dom/src/nodes/document/Document.ts index 44c0b560a..7a323d631 100644 --- a/packages/happy-dom/src/nodes/document/Document.ts +++ b/packages/happy-dom/src/nodes/document/Document.ts @@ -672,6 +672,18 @@ export default class Document extends Node { public querySelector(selector: string): Element | null { return QuerySelector.querySelector(this, selector); } + /** + * Returns true if the command is supported. + * @deprecated + * @param command Command. + * @returns True if the command is supported, false otherwise. + */ + public queryCommandSupported(command: string): boolean { + if (!command) { + throw new TypeError('Failed to execute \'queryCommandSupported\' on \'Document\': 1 argument required, but only 0 present.'); + } + return true + } /** * Returns an elements by class name. diff --git a/packages/happy-dom/test/nodes/document/Document.test.ts b/packages/happy-dom/test/nodes/document/Document.test.ts index 6b9332b4a..24c999662 100644 --- a/packages/happy-dom/test/nodes/document/Document.test.ts +++ b/packages/happy-dom/test/nodes/document/Document.test.ts @@ -598,6 +598,18 @@ describe('Document', () => { }); }); + describe('queryCommandSupported', () => { + it('Returns true if the command is supported.', () => { + // It's just a simple simulation implementation, and it will return true no matter what parameters are passed. + expect(document.queryCommandSupported('copy')).toBe(true); + expect(document.queryCommandSupported('selectall')).toBe(true); + }); + it('Throws an error if the command is not passed.', () => { + // @ts-ignore - Intentionally testing without parameters. + expect(() => document.queryCommandSupported()).toThrowError(new TypeError('Failed to execute \'queryCommandSupported\' on \'Document\': 1 argument required, but only 0 present.')); + }); + }) + describe('getElementsByClassName()', () => { it('Returns an elements by class name.', () => { const element = document.createElement('div'); From 95fc7e8751765a2874dcfa427e77047e31cb573a Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Mon, 22 Apr 2024 11:32:20 +0800 Subject: [PATCH 2/5] chore: lint --- .../happy-dom/src/nodes/document/Document.ts | 18 ++++++++++-------- .../test/nodes/document/Document.test.ts | 8 ++++++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/happy-dom/src/nodes/document/Document.ts b/packages/happy-dom/src/nodes/document/Document.ts index 7a323d631..3f6b03df6 100644 --- a/packages/happy-dom/src/nodes/document/Document.ts +++ b/packages/happy-dom/src/nodes/document/Document.ts @@ -673,16 +673,18 @@ export default class Document extends Node { return QuerySelector.querySelector(this, selector); } /** - * Returns true if the command is supported. - * @deprecated - * @param command Command. - * @returns True if the command is supported, false otherwise. - */ - public queryCommandSupported(command: string): boolean { + * Returns true if the command is supported. + * @deprecated + * @param command Command. + * @returns True if the command is supported, false otherwise. + */ + public queryCommandSupported(command: string): boolean { if (!command) { - throw new TypeError('Failed to execute \'queryCommandSupported\' on \'Document\': 1 argument required, but only 0 present.'); + throw new TypeError( + "Failed to execute 'queryCommandSupported' on 'Document': 1 argument required, but only 0 present." + ); } - return true + return true; } /** diff --git a/packages/happy-dom/test/nodes/document/Document.test.ts b/packages/happy-dom/test/nodes/document/Document.test.ts index 24c999662..a9b06876f 100644 --- a/packages/happy-dom/test/nodes/document/Document.test.ts +++ b/packages/happy-dom/test/nodes/document/Document.test.ts @@ -606,9 +606,13 @@ describe('Document', () => { }); it('Throws an error if the command is not passed.', () => { // @ts-ignore - Intentionally testing without parameters. - expect(() => document.queryCommandSupported()).toThrowError(new TypeError('Failed to execute \'queryCommandSupported\' on \'Document\': 1 argument required, but only 0 present.')); + expect(() => document.queryCommandSupported()).toThrowError( + new TypeError( + "Failed to execute 'queryCommandSupported' on 'Document': 1 argument required, but only 0 present." + ) + ); }); - }) + }); describe('getElementsByClassName()', () => { it('Returns an elements by class name.', () => { From d7b3f0539fb00c769379a58baa9c2b92324c5741 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Fri, 26 Apr 2024 09:07:52 +0800 Subject: [PATCH 3/5] fix: update --- packages/happy-dom/src/nodes/document/Document.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/happy-dom/src/nodes/document/Document.ts b/packages/happy-dom/src/nodes/document/Document.ts index 3f6b03df6..3e166987d 100644 --- a/packages/happy-dom/src/nodes/document/Document.ts +++ b/packages/happy-dom/src/nodes/document/Document.ts @@ -679,7 +679,7 @@ export default class Document extends Node { * @returns True if the command is supported, false otherwise. */ public queryCommandSupported(command: string): boolean { - if (!command) { + if (!arguments.length) { throw new TypeError( "Failed to execute 'queryCommandSupported' on 'Document': 1 argument required, but only 0 present." ); From ff075f9ab6de852b524135927861177920c4672f Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Fri, 26 Apr 2024 09:11:00 +0800 Subject: [PATCH 4/5] fix: update --- packages/happy-dom/src/nodes/document/Document.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/happy-dom/src/nodes/document/Document.ts b/packages/happy-dom/src/nodes/document/Document.ts index 3e166987d..791d7cbcc 100644 --- a/packages/happy-dom/src/nodes/document/Document.ts +++ b/packages/happy-dom/src/nodes/document/Document.ts @@ -675,10 +675,10 @@ export default class Document extends Node { /** * Returns true if the command is supported. * @deprecated - * @param command Command. + * @param _ Command. * @returns True if the command is supported, false otherwise. */ - public queryCommandSupported(command: string): boolean { + public queryCommandSupported(_: string): boolean { if (!arguments.length) { throw new TypeError( "Failed to execute 'queryCommandSupported' on 'Document': 1 argument required, but only 0 present." From 3a426bd1d15962c5e7cb056871f01ea768b4bbff Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Fri, 26 Apr 2024 09:13:58 +0800 Subject: [PATCH 5/5] fix: lint --- packages/happy-dom/src/nodes/document/Document.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/happy-dom/src/nodes/document/Document.ts b/packages/happy-dom/src/nodes/document/Document.ts index 791d7cbcc..0d08e1ef8 100644 --- a/packages/happy-dom/src/nodes/document/Document.ts +++ b/packages/happy-dom/src/nodes/document/Document.ts @@ -675,7 +675,7 @@ export default class Document extends Node { /** * Returns true if the command is supported. * @deprecated - * @param _ Command. + * @param _ Command. * @returns True if the command is supported, false otherwise. */ public queryCommandSupported(_: string): boolean {