Skip to content

fix(cdk/testing): fix change detection timing in testbed #20465

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

Merged
merged 1 commit into from
Sep 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions src/cdk/testing/testbed/unit-test-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,11 @@ export class UnitTestElement implements TestElement {
constructor(readonly element: Element, private _stabilize: () => Promise<void>) {}

async blur(): Promise<void> {
await this._stabilize();
triggerBlur(this.element as HTMLElement);
await this._stabilize();
}

async clear(): Promise<void> {
await this._stabilize();
if (!isTextInput(this.element)) {
throw Error('Attempting to clear an invalid element');
}
Expand All @@ -93,12 +91,10 @@ export class UnitTestElement implements TestElement {
this._dispatchPointerEventIfSupported('pointerup', clientX, clientY);
dispatchMouseEvent(this.element, 'mouseup', clientX, clientY);
dispatchMouseEvent(this.element, 'click', clientX, clientY);

await this._stabilize();
}

async focus(): Promise<void> {
await this._stabilize();
triggerFocus(this.element as HTMLElement);
await this._stabilize();
}
Expand All @@ -111,14 +107,12 @@ export class UnitTestElement implements TestElement {
}

async hover(): Promise<void> {
await this._stabilize();
this._dispatchPointerEventIfSupported('pointerenter');
dispatchMouseEvent(this.element, 'mouseenter');
await this._stabilize();
}

async mouseAway(): Promise<void> {
await this._stabilize();
this._dispatchPointerEventIfSupported('pointerleave');
dispatchMouseEvent(this.element, 'mouseleave');
await this._stabilize();
Expand All @@ -127,7 +121,6 @@ export class UnitTestElement implements TestElement {
async sendKeys(...keys: (string | TestKey)[]): Promise<void>;
async sendKeys(modifiers: ModifierKeys, ...keys: (string | TestKey)[]): Promise<void>;
async sendKeys(...modifiersAndKeys: any[]): Promise<void> {
await this._stabilize();
const args = modifiersAndKeys.map(k => typeof k === 'number' ? keyMap[k as TestKey] : k);
typeInElement(this.element as HTMLElement, ...args);
await this._stabilize();
Expand Down Expand Up @@ -162,8 +155,8 @@ export class UnitTestElement implements TestElement {
}

async setInputValue(value: string): Promise<void> {
await this._stabilize();
(this.element as any).value = value;
await this._stabilize();
}

async matchesSelector(selector: string): Promise<boolean> {
Expand Down