Skip to content

Commit c486cf8

Browse files
crisbetojelbourn
authored andcommitted
test(select): various test inconsistencies (#3861)
* 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. * chore: verify that changing the min-width causes failures * chore: revert min-width change * chore: remove a few unnecessary expressions
1 parent f40296e commit c486cf8

File tree

2 files changed

+37
-31
lines changed

2 files changed

+37
-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: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -988,37 +988,43 @@ 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', () => {
991+
it('should align the trigger and the selected option on the x-axis in ltr', async(() => {
992992
trigger.click();
993993
fixture.detectChanges();
994994

995-
const triggerLeft = trigger.getBoundingClientRect().left;
996-
const firstOptionLeft =
997-
document.querySelector('.cdk-overlay-pane md-option').getBoundingClientRect().left;
998-
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),
1003-
`Expected trigger to align with the selected option on the x-axis in LTR.`);
1004-
});
995+
fixture.whenStable().then(() => {
996+
const triggerLeft = trigger.getBoundingClientRect().left;
997+
const firstOptionLeft = document.querySelector('.cdk-overlay-pane md-option')
998+
.getBoundingClientRect().left;
999+
1000+
// Each option is 32px wider than the trigger, so it must be adjusted 16px
1001+
// to ensure the text overlaps correctly.
1002+
expect(firstOptionLeft.toFixed(2)).toEqual((triggerLeft - 16).toFixed(2),
1003+
`Expected trigger to align with the selected option on the x-axis in LTR.`);
1004+
});
1005+
}));
10051006

1006-
it('should align the trigger and the selected option on the x-axis in rtl', () => {
1007+
it('should align the trigger and the selected option on the x-axis in rtl', async(() => {
10071008
dir.value = 'rtl';
1009+
fixture.whenStable().then(() => {
1010+
fixture.detectChanges();
10081011

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;
1012+
trigger.click();
1013+
fixture.detectChanges();
10151014

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-
});
1015+
fixture.whenStable().then(() => {
1016+
const triggerRight = trigger.getBoundingClientRect().right;
1017+
const firstOptionRight =
1018+
document.querySelector('.cdk-overlay-pane md-option').getBoundingClientRect().right;
1019+
1020+
// Each option is 32px wider than the trigger, so it must be adjusted 16px
1021+
// to ensure the text overlaps correctly.
1022+
expect(firstOptionRight.toFixed(2))
1023+
.toEqual((triggerRight + 16).toFixed(2),
1024+
`Expected trigger to align with the selected option on the x-axis in RTL.`);
1025+
});
1026+
});
1027+
}));
10221028
});
10231029

10241030
describe('x-axis positioning in multi select mode', () => {
@@ -1450,13 +1456,13 @@ describe('MdSelect', () => {
14501456
let testInstance: MultiSelect;
14511457
let trigger: HTMLElement;
14521458

1453-
beforeEach(() => {
1459+
beforeEach(async(() => {
14541460
fixture = TestBed.createComponent(MultiSelect);
14551461
testInstance = fixture.componentInstance;
14561462
fixture.detectChanges();
14571463

14581464
trigger = fixture.debugElement.query(By.css('.mat-select-trigger')).nativeElement;
1459-
});
1465+
}));
14601466

14611467
it('should be able to select multiple values', () => {
14621468
trigger.click();
@@ -1616,17 +1622,17 @@ describe('MdSelect', () => {
16161622
expect(trigger.textContent).toContain('Tacos, Pizza, Steak');
16171623
});
16181624

1619-
it('should throw an exception when trying to set a non-array value', () => {
1625+
it('should throw an exception when trying to set a non-array value', async(() => {
16201626
expect(() => {
16211627
testInstance.control.setValue('not-an-array');
16221628
}).toThrowError(wrappedErrorMessage(new MdSelectNonArrayValueError()));
1623-
});
1629+
}));
16241630

1625-
it('should throw an exception when trying to change multiple mode after init', () => {
1631+
it('should throw an exception when trying to change multiple mode after init', async(() => {
16261632
expect(() => {
16271633
testInstance.select.multiple = false;
16281634
}).toThrowError(wrappedErrorMessage(new MdSelectDynamicMultipleError()));
1629-
});
1635+
}));
16301636

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

0 commit comments

Comments
 (0)