Skip to content

fix(input/testing): filtering by regex not working #20148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2020
Merged
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
8 changes: 4 additions & 4 deletions src/material/input/testing/input-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export class MatInputHarness extends MatFormFieldControlHarness {
*/
static with(options: InputHarnessFilters = {}): HarnessPredicate<MatInputHarness> {
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);
});
}

Expand Down
19 changes: 18 additions & 1 deletion src/material/input/testing/shared.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down