Skip to content

Commit 16f9f83

Browse files
crisbetowagnermaciel
authored andcommitted
fix(chips/testing): exclude icons from getText result (#20508)
Excludes the text of icons from the result of the `getText` method. Fixes #20503. (cherry picked from commit 20b4bc9)
1 parent 7d57fe0 commit 16f9f83

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

src/material-experimental/mdc-chips/testing/chip-harness.spec.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,24 @@ describe('MatChipHarness', () => {
2222

2323
it('should get correct number of chip harnesses', async () => {
2424
const harnesses = await loader.getAllHarnesses(MatChipHarness);
25-
expect(harnesses.length).toBe(3);
25+
expect(harnesses.length).toBe(4);
2626
});
2727

2828
it('should get the chip text content', async () => {
2929
const harnesses = await loader.getAllHarnesses(MatChipHarness);
3030
expect(await harnesses[0].getText()).toBe('Basic Chip');
3131
expect(await harnesses[1].getText()).toBe('Chip');
32-
expect(await harnesses[2].getText()).toBe('Disabled Chip');
32+
expect(await harnesses[2].getText()).toBe('Chip with avatar');
33+
expect(await harnesses[3].getText()).toBe('Disabled Chip');
3334
});
3435
});
3536

3637
@Component({
3738
template: `
38-
<mat-basic-chip> Basic Chip </mat-basic-chip>
39-
<mat-chip> Chip </mat-chip>
40-
<mat-chip disabled> Disabled Chip </mat-chip>
39+
<mat-basic-chip>Basic Chip</mat-basic-chip>
40+
<mat-chip>Chip <span matChipTrailingIcon>trailing_icon</span></mat-chip>
41+
<mat-chip><mat-chip-avatar>B</mat-chip-avatar>Chip with avatar</mat-chip>
42+
<mat-chip disabled>Disabled Chip <span matChipRemove>remove_icon</span></mat-chip>
4143
`
4244
})
4345
class ChipHarnessTest {}

src/material-experimental/mdc-chips/testing/chip-harness.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export class MatChipHarness extends ComponentHarness {
2626

2727
/** Gets a promise for the text content the option. */
2828
async getText(): Promise<string> {
29-
return (await this.host()).text();
29+
return (await this.host()).text({
30+
exclude: '.mat-mdc-chip-avatar, .mat-mdc-chip-trailing-icon, .mat-icon'
31+
});
3032
}
3133
}

src/material-experimental/mdc-chips/testing/chip-option-harness.spec.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,29 @@ describe('MatChipOptionHarness', () => {
3737
expect(await harnesses[0].isDisabled()).toBe(false);
3838
expect(await harnesses[3].isDisabled()).toBe(true);
3939
});
40+
41+
it('should get the chip text content', async () => {
42+
const harnesses = await loader.getAllHarnesses(MatChipOptionHarness);
43+
expect(await harnesses[0].getText()).toBe('Basic Chip Option');
44+
expect(await harnesses[1].getText()).toBe('Chip Option');
45+
expect(await harnesses[2].getText()).toBe('Selected Chip Option');
46+
expect(await harnesses[3].getText()).toBe('Chip Option');
47+
});
4048
});
4149

4250
@Component({
4351
template: `
4452
<mat-chip-listbox>
4553
<mat-basic-chip-option> Basic Chip Option </mat-basic-chip-option>
46-
<mat-chip-option> Chip Option </mat-chip-option>
47-
<mat-chip-option selected> Selected Chip Option </mat-chip-option>
48-
<mat-chip-option disabled> Chip Option </mat-chip-option>
54+
<mat-chip-option> <mat-chip-avatar>C</mat-chip-avatar>Chip Option </mat-chip-option>
55+
<mat-chip-option selected>
56+
Selected Chip Option
57+
<span matChipTrailingIcon>trailing_icon</span>
58+
</mat-chip-option>
59+
<mat-chip-option disabled>
60+
Chip Option
61+
<span matChipRemove>remove_icon</span>
62+
</mat-chip-option>
4963
</mat-chip-listbox>
5064
`
5165
})

src/material/chips/testing/chip-harness.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export class MatChipHarness extends ComponentHarness {
3131

3232
/** Gets the text of the chip. */
3333
async getText(): Promise<string> {
34-
return (await this.host()).text();
34+
return (await this.host()).text({
35+
exclude: '.mat-chip-avatar, .mat-chip-trailing-icon, .mat-icon'
36+
});
3537
}
3638

3739
/** Whether the chip is selected. */

src/material/chips/testing/shared.spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,14 @@ export function runHarnessTests(
306306
[multiple]="isMultiple"
307307
[aria-orientation]="orientation">
308308
<mat-chip (removed)="remove()">Chip 1</mat-chip>
309-
<mat-chip (removed)="remove()">Chip 2</mat-chip>
310-
<mat-chip disabled (removed)="remove()">Chip 3</mat-chip>
311-
<mat-chip (removed)="remove()">Chip 4</mat-chip>
309+
<mat-chip (removed)="remove()">Chip 2 <span matChipRemove>remove_icon</span></mat-chip>
310+
<mat-chip
311+
disabled
312+
(removed)="remove()">
313+
Chip 3
314+
<span matChipTrailingIcon>trailing_icon</span>
315+
</mat-chip>
316+
<mat-chip (removed)="remove()"><mat-chip-avatar>C</mat-chip-avatar>Chip 4</mat-chip>
312317
</mat-chip-list>
313318
314319
<mat-chip-list></mat-chip-list>

0 commit comments

Comments
 (0)