Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [#1411] Add queryCommandSupported method. #1412

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/happy-dom/src/nodes/document/Document.ts
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
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