MCPcopy Index your code
hub / github.com/angular/components / UnitTestElement

Class UnitTestElement

src/cdk/testing/testbed/unit-test-element.ts:68–405  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66
67/** A `TestElement` implementation for unit tests. */
68export class UnitTestElement implements TestElement {
69 constructor(
70 readonly element: Element,
71 private _stabilize: () => Promise<void>,
72 ) {}
73
74 /** Blur the element. */
75 async blur(): Promise<void> {
76 triggerBlur(this.element as HTMLElement);
77 await this._stabilize();
78 }
79
80 /** Clear the element's input (for input and textarea elements only). */
81 async clear(): Promise<void> {
82 if (!isTextInput(this.element)) {
83 throw Error('Attempting to clear an invalid element');
84 }
85 clearElement(this.element);
86 await this._stabilize();
87 }
88
89 /**
90 * Click the element at the default location for the current environment. If you need to guarantee
91 * the element is clicked at a specific location, consider using `click('center')` or
92 * `click(x, y)` instead.
93 */
94 click(modifiers?: ModifierKeys): Promise<void>;
95 /** Click the element at the element's center. */
96 click(location: 'center', modifiers?: ModifierKeys): Promise<void>;
97 /**
98 * Click the element at the specified coordinates relative to the top-left of the element.
99 * @param relativeX Coordinate within the element, along the X-axis at which to click.
100 * @param relativeY Coordinate within the element, along the Y-axis at which to click.
101 * @param modifiers Modifier keys held while clicking
102 */
103 click(relativeX: number, relativeY: number, modifiers?: ModifierKeys): Promise<void>;
104 async click(
105 ...args: [ModifierKeys?] | ['center', ModifierKeys?] | [number, number, ModifierKeys?]
106 ): Promise<void> {
107 const isDisabled = (this.element as Partial<{disabled?: boolean}>).disabled === true;
108
109 // If the element is `disabled` and has a `disabled` property, we emit the mouse event
110 // sequence but not dispatch the `click` event. This is necessary to keep the behavior
111 // consistent with an actual user interaction. The click event is not necessarily
112 // automatically prevented by the browser. There is mismatch between Firefox and Chromium:
113 // https://bugzilla.mozilla.org/show_bug.cgi?id=329509.
114 // https://bugs.chromium.org/p/chromium/issues/detail?id=1115661.
115 await this._dispatchMouseEventSequence(isDisabled ? null : 'click', args, 0);
116 await this._stabilize();
117 }
118
119 /**
120 * Right clicks on the element at the specified coordinates relative to the top-left of it.
121 * @param relativeX Coordinate within the element, along the X-axis at which to click.
122 * @param relativeY Coordinate within the element, along the Y-axis at which to click.
123 * @param modifiers Modifier keys held while clicking
124 */
125 rightClick(relativeX: number, relativeY: number, modifiers?: ModifierKeys): Promise<void>;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…