Skip to content

Commit abf069e

Browse files
committed
test(select): various test inconsistencies
* Fixes a select test that occasionally fails to capture the error inside the expect, causing it to get logged without actually being thrown. This seems to be a Zone-related issue since wrapping a few calls in `async` makes it behave correctly. * Fixes an RTL test that fails if it is made async. This incorporates the changes from #3866 and #3163 and fixes the underlying issue. It appears that the test was failing, because IE does a slight twitch on the select panel since it goes from a pixel-based `min-width` to one with `calc` and percentages to just percentages. I've set the default width to 100% which is the same as the pixel-based one, which appears to make IE happy.
1 parent e7a4a03 commit abf069e

File tree

2 files changed

+44
-31
lines changed

2 files changed

+44
-31
lines changed

src/lib/select/select.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ $mat-select-trigger-font-size: 16px !default;
125125
padding-top: 0;
126126
padding-bottom: 0;
127127
max-height: $mat-select-panel-max-height;
128+
min-width: 100%; // prevents some animation twitching and test inconsistencies in IE11
128129

129130
@include cdk-high-contrast {
130131
outline: solid 1px;
131132
}
132133
}
133-

src/lib/select/select.spec.ts

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -988,37 +988,50 @@ describe('MdSelect', () => {
988988
select.style.marginRight = '30px';
989989
});
990990

991-
it('should align the trigger and the selected option on the x-axis in ltr', () => {
992-
trigger.click();
993-
fixture.detectChanges();
991+
it('should align the trigger and the selected option on the x-axis in ltr', async(() => {
992+
fixture.whenStable().then(() => {
993+
fixture.detectChanges();
994994

995-
const triggerLeft = trigger.getBoundingClientRect().left;
996-
const firstOptionLeft =
997-
document.querySelector('.cdk-overlay-pane md-option').getBoundingClientRect().left;
995+
trigger.click();
996+
fixture.detectChanges();
998997

999-
// Each option is 32px wider than the trigger, so it must be adjusted 16px
1000-
// to ensure the text overlaps correctly.
1001-
expect(firstOptionLeft.toFixed(2))
1002-
.toEqual((triggerLeft - 16).toFixed(2),
998+
fixture.whenStable().then(() => {
999+
fixture.detectChanges();
1000+
1001+
const triggerLeft = trigger.getBoundingClientRect().left;
1002+
const firstOptionLeft = document.querySelector('.cdk-overlay-pane md-option')
1003+
.getBoundingClientRect().left;
1004+
1005+
// Each option is 32px wider than the trigger, so it must be adjusted 16px
1006+
// to ensure the text overlaps correctly.
1007+
expect(firstOptionLeft.toFixed(2)).toEqual((triggerLeft - 16).toFixed(2),
10031008
`Expected trigger to align with the selected option on the x-axis in LTR.`);
1004-
});
1009+
});
1010+
});
1011+
}));
10051012

1006-
it('should align the trigger and the selected option on the x-axis in rtl', () => {
1013+
it('should align the trigger and the selected option on the x-axis in rtl', async(() => {
10071014
dir.value = 'rtl';
1015+
fixture.whenStable().then(() => {
1016+
fixture.detectChanges();
10081017

1009-
trigger.click();
1010-
fixture.detectChanges();
1011-
1012-
const triggerRight = trigger.getBoundingClientRect().right;
1013-
const firstOptionRight =
1014-
document.querySelector('.cdk-overlay-pane md-option').getBoundingClientRect().right;
1018+
trigger.click();
1019+
fixture.detectChanges();
10151020

1016-
// Each option is 32px wider than the trigger, so it must be adjusted 16px
1017-
// to ensure the text overlaps correctly.
1018-
expect(firstOptionRight.toFixed(2))
1019-
.toEqual((triggerRight + 16).toFixed(2),
1020-
`Expected trigger to align with the selected option on the x-axis in RTL.`);
1021-
});
1021+
fixture.whenStable().then(() => {
1022+
fixture.detectChanges();
1023+
const triggerRight = trigger.getBoundingClientRect().right;
1024+
const firstOptionRight =
1025+
document.querySelector('.cdk-overlay-pane md-option').getBoundingClientRect().right;
1026+
1027+
// Each option is 32px wider than the trigger, so it must be adjusted 16px
1028+
// to ensure the text overlaps correctly.
1029+
expect(firstOptionRight.toFixed(2))
1030+
.toEqual((triggerRight + 16).toFixed(2),
1031+
`Expected trigger to align with the selected option on the x-axis in RTL.`);
1032+
});
1033+
});
1034+
}));
10221035
});
10231036

10241037
describe('x-axis positioning in multi select mode', () => {
@@ -1450,13 +1463,13 @@ describe('MdSelect', () => {
14501463
let testInstance: MultiSelect;
14511464
let trigger: HTMLElement;
14521465

1453-
beforeEach(() => {
1466+
beforeEach(async(() => {
14541467
fixture = TestBed.createComponent(MultiSelect);
14551468
testInstance = fixture.componentInstance;
14561469
fixture.detectChanges();
14571470

14581471
trigger = fixture.debugElement.query(By.css('.mat-select-trigger')).nativeElement;
1459-
});
1472+
}));
14601473

14611474
it('should be able to select multiple values', () => {
14621475
trigger.click();
@@ -1616,17 +1629,17 @@ describe('MdSelect', () => {
16161629
expect(trigger.textContent).toContain('Tacos, Pizza, Steak');
16171630
});
16181631

1619-
it('should throw an exception when trying to set a non-array value', () => {
1632+
it('should throw an exception when trying to set a non-array value', async(() => {
16201633
expect(() => {
16211634
testInstance.control.setValue('not-an-array');
16221635
}).toThrowError(wrappedErrorMessage(new MdSelectNonArrayValueError()));
1623-
});
1636+
}));
16241637

1625-
it('should throw an exception when trying to change multiple mode after init', () => {
1638+
it('should throw an exception when trying to change multiple mode after init', async(() => {
16261639
expect(() => {
16271640
testInstance.select.multiple = false;
16281641
}).toThrowError(wrappedErrorMessage(new MdSelectDynamicMultipleError()));
1629-
});
1642+
}));
16301643

16311644
it('should pass the `multiple` value to all of the option instances', async(() => {
16321645
trigger.click();

0 commit comments

Comments
 (0)