Skip to content

Commit

Permalink
fixup! fix(material/form-field): allow getting harness by validity
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba committed Dec 12, 2022
1 parent 3475e30 commit 7b2e728
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
Expand Up @@ -15,5 +15,5 @@ export interface FormFieldHarnessFilters extends BaseHarnessFilters {
/** Filters based on whether the form field has error messages. */
hasErrors?: boolean;
/** Filters based on whether the form field value is valid. */
valid?: boolean;
isValid?: boolean;
}
6 changes: 3 additions & 3 deletions src/material/form-field/testing/form-field-harness.ts
Expand Up @@ -250,9 +250,9 @@ export class MatFormFieldHarness extends _MatFormFieldHarnessBase<
async (harness, hasErrors) => (await harness.hasErrors()) === hasErrors,
)
.addOption(
'valid',
options.valid,
async (harness, valid) => (await harness.isControlValid()) === valid,
'isValid',
options.isValid,
async (harness, isValid) => (await harness.isControlValid()) === isValid,
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/material/form-field/testing/shared.spec.ts
Expand Up @@ -198,13 +198,13 @@ export function runHarnessTests(
});

it('should be able to get form-field by validity', async () => {
let invalid = await loader.getAllHarnesses(formFieldHarness.with({valid: false}));
let invalid = await loader.getAllHarnesses(formFieldHarness.with({isValid: false}));
expect(invalid.length).toBe(0);

fixture.componentInstance.requiredControl.setValue('');
dispatchFakeEvent(fixture.nativeElement.querySelector('#with-errors input'), 'blur');

invalid = await loader.getAllHarnesses(formFieldHarness.with({valid: false}));
invalid = await loader.getAllHarnesses(formFieldHarness.with({isValid: false}));
expect(invalid.length).toBe(1);
});

Expand Down
6 changes: 3 additions & 3 deletions src/material/legacy-form-field/testing/form-field-harness.ts
Expand Up @@ -59,9 +59,9 @@ export class MatLegacyFormFieldHarness extends _MatFormFieldHarnessBase<
async (harness, hasErrors) => (await harness.hasErrors()) === hasErrors,
)
.addOption(
'valid',
options.valid,
async (harness, valid) => (await harness.isControlValid()) === valid,
'isValid',
options.isValid,
async (harness, isValid) => (await harness.isControlValid()) === isValid,
);
}

Expand Down
1 change: 1 addition & 0 deletions tools/public_api_guard/material/form-field-testing.md
Expand Up @@ -28,6 +28,7 @@ export type FormFieldControlHarness = MatInputHarness | MatSelectHarness | MatDa
export interface FormFieldHarnessFilters extends BaseHarnessFilters {
floatingLabelText?: string | RegExp;
hasErrors?: boolean;
isValid?: boolean;
}

// @public
Expand Down

0 comments on commit 7b2e728

Please sign in to comment.