Skip to content

Commit e422225

Browse files
asynclizcopybara-github
authored andcommitted
feat(testing): refactor harness and add more simulation methods
PiperOrigin-RevId: 449012371
1 parent 3b221d8 commit e422225

File tree

8 files changed

+312
-267
lines changed

8 files changed

+312
-267
lines changed

components/button/harness.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ export class ButtonHarness extends Harness<Button> {
1717
return this.element.renderRoot.querySelector('.md3-button') as HTMLElement;
1818
}
1919

20-
override async press() {
21-
await this.hoverEnter();
22-
await super.press();
20+
override async clickWithMouseStart(init: PointerEventInit = {}) {
21+
await super.clickWithMouseStart(init);
2322
// The ripple adapter unconditionally returns true for
2423
// `containsEventTarget`, which effectively blocks simultaneous ripple
2524
// activations. We need simulatenous activations for testing though, so

components/checkbox/md-checkbox_test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ describe('md-checkbox', () => {
6060
});
6161

6262
it('user input updates checked state', async () => {
63-
await harness.click();
63+
await harness.clickWithMouse();
6464
await element.updateComplete;
6565
expect(element.checked).toEqual(true);
6666
});
6767

6868
it('change event has updated values for `checked`', async () => {
6969
expect(element.checked).toBeFalse();
70-
await harness.click();
70+
await harness.clickWithMouse();
7171
expect(element.checked).toBeTrue();
7272
});
7373

@@ -77,7 +77,7 @@ describe('md-checkbox', () => {
7777
element.addEventListener('action', (e: Event) => {
7878
actionEvent = e as CustomEvent;
7979
});
80-
await harness.click();
80+
await harness.clickWithMouse();
8181
await element.updateComplete;
8282

8383
expect(actionEvent).toBeInstanceOf(CustomEvent);
@@ -173,7 +173,7 @@ describe('md-checkbox', () => {
173173
});
174174

175175
it('hidden on non-keyboard focus', async () => {
176-
await harness.click();
176+
await harness.clickWithMouse();
177177
expect(focusRing.visible).toBeFalse();
178178
});
179179

@@ -187,7 +187,7 @@ describe('md-checkbox', () => {
187187
it('hidden after pointer interaction', async () => {
188188
await harness.focusWithKeyboard();
189189
expect(focusRing.visible).toBeTrue();
190-
await harness.click();
190+
await harness.clickWithMouse();
191191
expect(focusRing.visible).toBeFalse();
192192
});
193193
});

0 commit comments

Comments
 (0)