Skip to content

Commit

Permalink
Merge pull request #1412 from btea/feature/add-queryCommandSupported
Browse files Browse the repository at this point in the history
feat: [#1411] Add queryCommandSupported method.
  • Loading branch information
capricorn86 committed May 6, 2024
2 parents 7a5b003 + 9bf6a59 commit 2e03291
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/happy-dom/src/nodes/document/Document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,20 @@ 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.
* @returns True if the command is supported, false otherwise.
*/
public queryCommandSupported(_: string): boolean {
if (!arguments.length) {
throw new TypeError(
"Failed to execute 'queryCommandSupported' on 'Document': 1 argument required, but only 0 present."
);
}
return true;
}

/**
* Returns an elements by class name.
Expand Down
16 changes: 16 additions & 0 deletions packages/happy-dom/test/nodes/document/Document.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,22 @@ 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');
Expand Down

0 comments on commit 2e03291

Please sign in to comment.