diff --git a/src/material/input/testing/input-harness.spec.ts b/src/material/input/testing/input-harness.spec.ts index 20382ca4fe29..fc9c9cf3cdd0 100644 --- a/src/material/input/testing/input-harness.spec.ts +++ b/src/material/input/testing/input-harness.spec.ts @@ -124,6 +124,15 @@ describe('MatInputHarness', () => { expect(await inputs[4].getValue()).toBe('new-value'); }); + it('should dispatch a change event when setting the value', async () => { + const input = await loader.getHarness(MatInputHarness.with({selector: '#myTextarea'})); + expect(fixture.componentInstance.textareaChangeCount).toBe(0); + + await input.setValue('new-value'); + + expect(fixture.componentInstance.textareaChangeCount).toBe(1); + }); + it('should be able to get disabled state', async () => { const inputs = await loader.getAllHarnesses(MatInputHarness); expect(inputs.length).toBe(7); @@ -267,6 +276,7 @@ describe('MatInputHarness', () => { matInput placeholder="Leave a comment" aria-label="Comment box" + (change)="textareaChangeCount = textareaChangeCount + 1" > @@ -307,4 +317,5 @@ class InputHarnessTest { required = signal(false); ngModelValue = ''; ngModelName = 'has-ng-model'; + textareaChangeCount = 0; } diff --git a/src/material/input/testing/input-harness.ts b/src/material/input/testing/input-harness.ts index c88101a32ad9..fe7aeb2376dd 100644 --- a/src/material/input/testing/input-harness.ts +++ b/src/material/input/testing/input-harness.ts @@ -136,5 +136,9 @@ export class MatInputHarness extends MatFormFieldControlHarnessBase { // value is set, we also set the property after the keyboard sequence. Note that we don't // want to do it before, because it can cause the value to be entered twice. await inputEl.setInputValue(newValue); + + // Dispatch a `change` event so that listeners bound to it are notified, similarly + // to what happens when the user commits a value by blurring the input. + await inputEl.dispatchEvent('change'); } }