Skip to content

Commit 5453d91

Browse files
authored
fix: remove element selectors from test harnesses (#20224)
We're using element selectors for some of the test harnesses which can conflict between the MDC and non-MDC components. These changes switch them to use class selectors, similarly to what we decided to do for the MDC component styles.
1 parent 199f728 commit 5453d91

File tree

29 files changed

+31
-30
lines changed

29 files changed

+31
-30
lines changed

src/material-experimental/mdc-checkbox/testing/checkbox-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {CheckboxHarnessFilters} from '@angular/material/checkbox/testing';
1212

1313
/** Harness for interacting with a MDC-based mat-checkbox in tests. */
1414
export class MatCheckboxHarness extends ComponentHarness {
15-
static hostSelector = 'mat-checkbox';
15+
static hostSelector = '.mat-mdc-checkbox';
1616

1717
/**
1818
* Gets a `HarnessPredicate` that can be used to search for a checkbox with specific attributes.

src/material-experimental/mdc-chips/chip-option.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class MatChipSelectionChange {
4444
inputs: ['color', 'disableRipple', 'tabIndex'],
4545
host: {
4646
'role': 'option',
47-
'class': 'mat-mdc-focus-indicator',
47+
'class': 'mat-mdc-focus-indicator mat-mdc-chip-option',
4848
'[class.mat-mdc-chip-disabled]': 'disabled',
4949
'[class.mat-mdc-chip-highlighted]': 'highlighted',
5050
'[class.mat-mdc-chip-with-avatar]': 'leadingIcon',

src/material-experimental/mdc-chips/chip-row.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export interface MatChipEditedEvent extends MatChipEvent {
5050
inputs: ['color', 'disableRipple', 'tabIndex'],
5151
host: {
5252
'role': 'row',
53+
'class': 'mat-mdc-chip-row',
5354
'[class.mat-mdc-chip-disabled]': 'disabled',
5455
'[class.mat-mdc-chip-highlighted]': 'highlighted',
5556
'[class.mat-mdc-chip-with-avatar]': 'leadingIcon',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {MatChipRowHarness} from './chip-row-harness';
1313

1414
/** Harness for interacting with a mat-chip-grid in tests. */
1515
export class MatChipGridHarness extends ComponentHarness {
16-
static hostSelector = 'mat-chip-grid';
16+
static hostSelector = '.mat-mdc-chip-grid';
1717

1818
/**
1919
* Gets a `HarnessPredicate` that can be used to search for a chip grid with specific attributes.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {ChipHarnessFilters} from './chip-harness-filters';
1111

1212
/** Harness for interacting with a mat-chip in tests. */
1313
export class MatChipHarness extends ComponentHarness {
14-
static hostSelector = 'mat-basic-chip, mat-chip';
14+
static hostSelector = '.mat-mdc-basic-chip, .mat-mdc-chip';
1515

1616
/**
1717
* Gets a `HarnessPredicate` that can be used to search for a chip with specific attributes.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {MatChipOptionHarness} from './chip-option-harness';
1212

1313
/** Harness for interacting with a mat-chip-listbox in tests. */
1414
export class MatChipListboxHarness extends ComponentHarness {
15-
static hostSelector = 'mat-chip-listbox';
15+
static hostSelector = '.mat-mdc-chip-listbox';
1616

1717
/**
1818
* Gets a `HarnessPredicate` that can be used to search for a chip listbox with specific

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {ChipOptionHarnessFilters} from './chip-harness-filters';
1212

1313
/** Harness for interacting with a mat-chip-option in tests. */
1414
export class MatChipOptionHarness extends MatChipHarness {
15-
static hostSelector = 'mat-basic-chip-option, mat-chip-option';
15+
static hostSelector = '.mat-mdc-chip-option';
1616

1717
/**
1818
* Gets a `HarnessPredicate` that can be used to search for a chip option with specific

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {MatChipHarness} from './chip-harness';
1212

1313
/** Harness for interacting with a mat-chip-row in tests. */
1414
export class MatChipRowHarness extends MatChipHarness {
15-
static hostSelector = 'mat-chip-row, mat-basic-chip-row';
15+
static hostSelector = '.mat-mdc-chip-row';
1616

1717
/**
1818
* Gets a `HarnessPredicate` that can be used to search for a chip row with specific attributes.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {ChipSetHarnessFilters} from './chip-harness-filters';
1212

1313
/** Harness for interacting with a mat-chip-set in tests. */
1414
export class MatChipSetHarness extends ComponentHarness {
15-
static hostSelector = 'mat-chip-set';
15+
static hostSelector = '.mat-mdc-chip-set';
1616

1717
/**
1818
* Gets a `HarnessPredicate` that can be used to search for a chip set with specific attributes.

src/material-experimental/mdc-progress-bar/testing/progress-bar-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {ProgressBarHarnessFilters} from '@angular/material/progress-bar/testing'
1212

1313
/** Harness for interacting with an MDC-based `mat-progress-bar` in tests. */
1414
export class MatProgressBarHarness extends ComponentHarness {
15-
static hostSelector = 'mat-progress-bar';
15+
static hostSelector = '.mat-mdc-progress-bar';
1616

1717
/**
1818
* Gets a `HarnessPredicate` that can be used to search for a progress bar with specific

src/material-experimental/mdc-progress-spinner/testing/progress-spinner-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {ProgressSpinnerHarnessFilters} from '@angular/material/progress-spinner/
1414
/** Harness for interacting with a MDC based mat-progress-spinner in tests. */
1515
export class MatProgressSpinnerHarness extends ComponentHarness {
1616
/** The selector for the host element of a `MatProgressSpinner` instance. */
17-
static hostSelector = 'mat-progress-spinner,mat-spinner';
17+
static hostSelector = '.mat-mdc-progress-spinner';
1818

1919
/**
2020
* Gets a `HarnessPredicate` that can be used to search for a `MatProgressSpinnerHarness` that

src/material-experimental/mdc-slide-toggle/testing/slide-toggle-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {SlideToggleHarnessFilters} from '@angular/material/slide-toggle/testing'
1313

1414
/** Harness for interacting with a MDC-based mat-slide-toggle in tests. */
1515
export class MatSlideToggleHarness extends ComponentHarness {
16-
static hostSelector = 'mat-slide-toggle';
16+
static hostSelector = '.mat-mdc-slide-toggle';
1717

1818
/**
1919
* Gets a `HarnessPredicate` that can be used to search for a slide-toggle w/ specific attributes.

src/material-experimental/mdc-slider/testing/slider-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {SliderHarnessFilters} from '@angular/material/slider/testing';
1212

1313
/** Harness for interacting with a MDC mat-slider in tests. */
1414
export class MatSliderHarness extends ComponentHarness {
15-
static hostSelector = 'mat-slider';
15+
static hostSelector = '.mat-mdc-slider';
1616

1717
/**
1818
* Gets a `HarnessPredicate` that can be used to search for a mat-slider with

src/material/button-toggle/testing/button-toggle-group-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {MatButtonToggleHarness} from './button-toggle-harness';
1616
/** Harness for interacting with a standard mat-button-toggle in tests. */
1717
export class MatButtonToggleGroupHarness extends ComponentHarness {
1818
/** The selector for the host element of a `MatButton` instance. */
19-
static hostSelector = 'mat-button-toggle-group';
19+
static hostSelector = '.mat-button-toggle-group';
2020

2121
/**
2222
* Gets a `HarnessPredicate` that can be used to search for a `MatButtonToggleGroupHarness`

src/material/button-toggle/testing/button-toggle-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {ButtonToggleHarnessFilters} from './button-toggle-harness-filters';
1515
/** Harness for interacting with a standard mat-button-toggle in tests. */
1616
export class MatButtonToggleHarness extends ComponentHarness {
1717
/** The selector for the host element of a `MatButton` instance. */
18-
static hostSelector = 'mat-button-toggle';
18+
static hostSelector = '.mat-button-toggle';
1919

2020
private _label = this.locatorFor('.mat-button-toggle-label-content');
2121
private _button = this.locatorFor('.mat-button-toggle-button');

src/material/card/testing/card-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const enum MatCardSection {
2020
/** Harness for interacting with a standard mat-card in tests. */
2121
export class MatCardHarness extends ContentContainerComponentHarness<MatCardSection> {
2222
/** The selector for the host element of a `MatCard` instance. */
23-
static hostSelector = 'mat-card';
23+
static hostSelector = '.mat-card';
2424

2525
/**
2626
* Gets a `HarnessPredicate` that can be used to search for a `MatCardHarness` that meets

src/material/checkbox/testing/checkbox-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {CheckboxHarnessFilters} from './checkbox-harness-filters';
1313
/** Harness for interacting with a standard mat-checkbox in tests. */
1414
export class MatCheckboxHarness extends ComponentHarness {
1515
/** The selector for the host element of a `MatCheckbox` instance. */
16-
static hostSelector = 'mat-checkbox';
16+
static hostSelector = '.mat-checkbox';
1717

1818
/**
1919
* Gets a `HarnessPredicate` that can be used to search for a `MatCheckboxHarness` that meets

src/material/divider/testing/divider-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {DividerHarnessFilters} from './divider-harness-filters';
1414
* @dynamic
1515
*/
1616
export class MatDividerHarness extends ComponentHarness {
17-
static hostSelector = 'mat-divider';
17+
static hostSelector = '.mat-divider';
1818

1919
static with(options: DividerHarnessFilters = {}) {
2020
return new HarnessPredicate(MatDividerHarness, options);

src/material/list/testing/action-list-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {getListItemPredicate, MatListItemHarnessBase} from './list-item-harness-
1515
export class MatActionListHarness extends MatListHarnessBase<
1616
typeof MatActionListItemHarness, MatActionListItemHarness, ActionListItemHarnessFilters> {
1717
/** The selector for the host element of a `MatActionList` instance. */
18-
static hostSelector = 'mat-action-list';
18+
static hostSelector = 'mat-action-list.mat-list';
1919

2020
/**
2121
* Gets a `HarnessPredicate` that can be used to search for a `MatActionListHarness` that meets

src/material/list/testing/list-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {getListItemPredicate, MatListItemHarnessBase} from './list-item-harness-
1515
export class MatListHarness extends
1616
MatListHarnessBase<typeof MatListItemHarness, MatListItemHarness, ListItemHarnessFilters> {
1717
/** The selector for the host element of a `MatList` instance. */
18-
static hostSelector = 'mat-list';
18+
static hostSelector = '.mat-list:not(mat-action-list):not(mat-nav-list):not(mat-selection-list)';
1919

2020
/**
2121
* Gets a `HarnessPredicate` that can be used to search for a `MatListHarness` that meets certain

src/material/list/testing/list-item-harness-base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function getListItemPredicate<H extends MatListItemHarnessBase>(
3232

3333
/** Harness for interacting with a list subheader. */
3434
export class MatSubheaderHarness extends ComponentHarness {
35-
static hostSelector = '[mat-subheader], [matSubheader]';
35+
static hostSelector = '.mat-subheader';
3636

3737
static with(options: SubheaderHarnessFilters = {}): HarnessPredicate<MatSubheaderHarness> {
3838
return new HarnessPredicate(MatSubheaderHarness, options)

src/material/list/testing/nav-list-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {getListItemPredicate, MatListItemHarnessBase} from './list-item-harness-
1515
export class MatNavListHarness extends MatListHarnessBase<
1616
typeof MatNavListItemHarness, MatNavListItemHarness, NavListItemHarnessFilters> {
1717
/** The selector for the host element of a `MatNavList` instance. */
18-
static hostSelector = 'mat-nav-list';
18+
static hostSelector = '.mat-nav-list';
1919

2020
/**
2121
* Gets a `HarnessPredicate` that can be used to search for a `MatNavListHarness` that meets

src/material/list/testing/selection-list-harness.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {getListItemPredicate, MatListItemHarnessBase} from './list-item-harness-
1919
export class MatSelectionListHarness extends MatListHarnessBase<
2020
typeof MatListOptionHarness, MatListOptionHarness, ListOptionHarnessFilters> {
2121
/** The selector for the host element of a `MatSelectionList` instance. */
22-
static hostSelector = 'mat-selection-list';
22+
static hostSelector = '.mat-selection-list';
2323

2424
/**
2525
* Gets a `HarnessPredicate` that can be used to search for a `MatSelectionListHarness` that meets
@@ -70,7 +70,7 @@ export class MatSelectionListHarness extends MatListHarnessBase<
7070
/** Harness for interacting with a list option. */
7171
export class MatListOptionHarness extends MatListItemHarnessBase {
7272
/** The selector for the host element of a `MatListOption` instance. */
73-
static hostSelector = 'mat-list-option';
73+
static hostSelector = '.mat-list-option';
7474

7575
/**
7676
* Gets a `HarnessPredicate` that can be used to search for a `MatListOptionHarness` that

src/material/progress-bar/testing/progress-bar-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {ProgressBarHarnessFilters} from './progress-bar-harness-filters';
1313
/** Harness for interacting with a standard mat-progress-bar in tests. */
1414
export class MatProgressBarHarness extends ComponentHarness {
1515
/** The selector for the host element of a `MatProgressBar` instance. */
16-
static hostSelector = 'mat-progress-bar';
16+
static hostSelector = '.mat-progress-bar';
1717

1818
/**
1919
* Gets a `HarnessPredicate` that can be used to search for a `MatProgressBarHarness` that meets

src/material/progress-spinner/testing/progress-spinner-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {ProgressSpinnerHarnessFilters} from './progress-spinner-harness-filters'
1414
/** Harness for interacting with a standard mat-progress-spinner in tests. */
1515
export class MatProgressSpinnerHarness extends ComponentHarness {
1616
/** The selector for the host element of a `MatProgressSpinner` instance. */
17-
static hostSelector = 'mat-progress-spinner,mat-spinner';
17+
static hostSelector = '.mat-progress-spinner';
1818

1919
/**
2020
* Gets a `HarnessPredicate` that can be used to search for a `MatProgressSpinnerHarness` that

src/material/radio/testing/radio-harness.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {RadioButtonHarnessFilters, RadioGroupHarnessFilters} from './radio-harne
1313
/** Harness for interacting with a standard mat-radio-group in tests. */
1414
export class MatRadioGroupHarness extends ComponentHarness {
1515
/** The selector for the host element of a `MatRadioGroup` instance. */
16-
static hostSelector = 'mat-radio-group';
16+
static hostSelector = '.mat-radio-group';
1717

1818
/**
1919
* Gets a `HarnessPredicate` that can be used to search for a `MatRadioGroupHarness` that meets
@@ -156,7 +156,7 @@ export class MatRadioGroupHarness extends ComponentHarness {
156156
/** Harness for interacting with a standard mat-radio-button in tests. */
157157
export class MatRadioButtonHarness extends ComponentHarness {
158158
/** The selector for the host element of a `MatRadioButton` instance. */
159-
static hostSelector = 'mat-radio-button';
159+
static hostSelector = '.mat-radio-button';
160160

161161
/**
162162
* Gets a `HarnessPredicate` that can be used to search for a `MatRadioButtonHarness` that meets

src/material/slide-toggle/testing/slide-toggle-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {SlideToggleHarnessFilters} from './slide-toggle-harness-filters';
1414
/** Harness for interacting with a standard mat-slide-toggle in tests. */
1515
export class MatSlideToggleHarness extends ComponentHarness {
1616
/** The selector for the host element of a `MatSlideToggle` instance. */
17-
static hostSelector = 'mat-slide-toggle';
17+
static hostSelector = '.mat-slide-toggle';
1818

1919
/**
2020
* Gets a `HarnessPredicate` that can be used to search for a `MatSlideToggleHarness` that meets

src/material/slider/testing/slider-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {SliderHarnessFilters} from './slider-harness-filters';
1313
/** Harness for interacting with a standard mat-slider in tests. */
1414
export class MatSliderHarness extends ComponentHarness {
1515
/** The selector for the host element of a `MatSlider` instance. */
16-
static hostSelector = 'mat-slider';
16+
static hostSelector = '.mat-slider';
1717

1818
/**
1919
* Gets a `HarnessPredicate` that can be used to search for a `MatSliderHarness` that meets

src/material/toolbar/testing/toolbar-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const enum MatToolbarSection {
1717

1818
/** Harness for interacting with a standard mat-toolbar in tests. */
1919
export class MatToolbarHarness extends ContentContainerComponentHarness<MatToolbarSection> {
20-
static hostSelector = 'mat-toolbar';
20+
static hostSelector = '.mat-toolbar';
2121

2222
private _getRows = this.locatorForAll(MatToolbarSection.ROW);
2323

0 commit comments

Comments
 (0)