Skip to content

Commit

Permalink
fix(cdk/testing): fix change detection timing in testbed (#20465)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba committed Sep 2, 2020
1 parent ecde050 commit 29468fa
Showing 1 changed file with 1 addition and 8 deletions.
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

0 comments on commit 29468fa

Please sign in to comment.