Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions src/material/input/testing/input-harness.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -267,6 +276,7 @@ describe('MatInputHarness', () => {
matInput
placeholder="Leave a comment"
aria-label="Comment box"
(change)="textareaChangeCount = textareaChangeCount + 1"
></textarea>
</mat-form-field>

Expand Down Expand Up @@ -307,4 +317,5 @@ class InputHarnessTest {
required = signal(false);
ngModelValue = '';
ngModelName = 'has-ng-model';
textareaChangeCount = 0;
}
4 changes: 4 additions & 0 deletions src/material/input/testing/input-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Loading