diff --git a/src/material/input/testing/input-harness.ts b/src/material/input/testing/input-harness.ts index 0aef7a8d242c..345f0272afbd 100644 --- a/src/material/input/testing/input-harness.ts +++ b/src/material/input/testing/input-harness.ts @@ -25,11 +25,11 @@ export class MatInputHarness extends MatFormFieldControlHarness { */ static with(options: InputHarnessFilters = {}): HarnessPredicate { return new HarnessPredicate(MatInputHarness, options) - .addOption('value', options.value, async (harness, value) => { - return (await harness.getValue()) === value; + .addOption('value', options.value, (harness, value) => { + return HarnessPredicate.stringMatches(harness.getValue(), value); }) - .addOption('placeholder', options.placeholder, async (harness, placeholder) => { - return (await harness.getPlaceholder()) === placeholder; + .addOption('placeholder', options.placeholder, (harness, placeholder) => { + return HarnessPredicate.stringMatches(harness.getPlaceholder(), placeholder); }); } diff --git a/src/material/input/testing/shared.spec.ts b/src/material/input/testing/shared.spec.ts index 9e6a91224db0..b821d3580efb 100644 --- a/src/material/input/testing/shared.spec.ts +++ b/src/material/input/testing/shared.spec.ts @@ -43,11 +43,28 @@ export function runHarnessTests( expect(inputs.length).toBe(1); }); - it('should load input with specific value', async () => { + it('should load input with a specific value', async () => { const inputs = await loader.getAllHarnesses(inputHarness.with({value: 'Sushi'})); expect(inputs.length).toBe(1); }); + it('should load input with a value that matches a regex', async () => { + const inputs = await loader.getAllHarnesses(inputHarness.with({value: /shi$/})); + expect(inputs.length).toBe(1); + expect(await inputs[0].getValue()).toBe('Sushi'); + }); + + it('should load input with a specific placeholder', async () => { + const inputs = await loader.getAllHarnesses(inputHarness.with({placeholder: 'Favorite food'})); + expect(inputs.length).toBe(1); + }); + + it('should load input with a placeholder that matches a regex', async () => { + const inputs = await loader.getAllHarnesses(inputHarness.with({placeholder: / food$/})); + expect(inputs.length).toBe(1); + expect(await inputs[0].getPlaceholder()).toBe('Favorite food'); + }); + it('should be able to get id of input', async () => { const inputs = await loader.getAllHarnesses(inputHarness); expect(inputs.length).toBe(6);