Skip to content

Commit e725863

Browse files
wagnermacielamysorto
authored andcommitted
fix(material-experimental/mdc-slider): correct description of slider … (#23431)
* fix(material-experimental/mdc-slider): correct description of slider harness thumb getters * fix(material-experimental/mdc-slider): throw helpful error when wrong slider thumb getter is used * added a unit test to make sure this error works properly (cherry picked from commit c4cf3c9)
1 parent 1244e25 commit e725863

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ describe('MDC-based MatSliderHarness', () => {
6868
expect(await sliders[1].getEndThumb()).toBeTruthy();
6969
});
7070

71+
it('should throw when trying to get the start thumb from a single point slider', async () => {
72+
const slider = await loader.getHarness(MatSliderHarness.with({isRange: false}));
73+
await expectAsync(slider.getStartThumb()).toBeRejectedWithError(
74+
'`getStartThumb` is only applicable for range sliders. '
75+
+ 'Did you mean to use `getEndThumb`?',
76+
);
77+
});
78+
7179
it('should get the step of a slider', async () => {
7280
const sliders = await loader.getAllHarnesses(MatSliderHarness);
7381
expect(await parallel(() => {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,18 @@ export class MatSliderHarness extends ComponentHarness {
2828
});
2929
}
3030

31-
/** Gets the start/primary thumb of the slider. */
31+
/** Gets the start thumb of the slider (only applicable for range sliders). */
3232
async getStartThumb(): Promise<MatSliderThumbHarness> {
33+
if (!await this.isRange()) {
34+
throw Error(
35+
'`getStartThumb` is only applicable for range sliders. '
36+
+ 'Did you mean to use `getEndThumb`?'
37+
);
38+
}
3339
return this.locatorFor(MatSliderThumbHarness.with({position: ThumbPosition.START}))();
3440
}
3541

36-
/** Gets the end thumb of the slider. Will throw an error for a non-range slider. */
42+
/** Gets the thumb (for single point sliders), or the end thumb (for range sliders). */
3743
async getEndThumb(): Promise<MatSliderThumbHarness> {
3844
return this.locatorFor(MatSliderThumbHarness.with({position: ThumbPosition.END}))();
3945
}

0 commit comments

Comments
 (0)