Skip to content

Commit f595c70

Browse files
jeripeierSBBandrewseguin
authored andcommitted
test(material/select): remove form-field dependency in deselection test (#21963)
The existing test would not work without using mat-form-field wrapper because the trigger.click() propagates to onContainerClick of FormField which calls select.open() a second time. With this change, the logic does not base on propagating/onContainerClick but on specific open and close commands of the panel. (cherry picked from commit dd4a171)
1 parent 3a125ce commit f595c70

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/material-experimental/mdc-select/select.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ describe('MDC-based MatSelect', () => {
8989
* that we're only compiling the necessary test components for each test in order to speed up
9090
* overall test time.
9191
* @param declarations Components to declare for this block
92+
* @param providers Additional providers for this block
9293
*/
9394
function configureMatSelectTestingModule(declarations: any[], providers: Provider[] = []) {
9495
TestBed.configureTestingModule({
@@ -1088,7 +1089,7 @@ describe('MDC-based MatSelect', () => {
10881089

10891090
options[1].click();
10901091
fixture.detectChanges();
1091-
trigger.click();
1092+
fixture.componentInstance.select.open();
10921093
fixture.detectChanges();
10931094
flush();
10941095

@@ -1100,10 +1101,13 @@ describe('MDC-based MatSelect', () => {
11001101

11011102
fixture.componentInstance.control.setValue(fixture.componentInstance.foods[7].value);
11021103
fixture.detectChanges();
1103-
trigger.click();
1104+
fixture.componentInstance.select.close();
11041105
fixture.detectChanges();
11051106
flush();
11061107

1108+
fixture.componentInstance.select.open();
1109+
fixture.detectChanges();
1110+
11071111
activeOptions = options.filter(option => {
11081112
return option.classList.contains('mat-mdc-option-active');
11091113
});

src/material/select/select.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ describe('MatSelect', () => {
9191
* that we're only compiling the necessary test components for each test in order to speed up
9292
* overall test time.
9393
* @param declarations Components to declare for this block
94+
* @param providers Additional providers for this block
9495
*/
9596
function configureMatSelectTestingModule(declarations: any[], providers: Provider[] = []) {
9697
TestBed.configureTestingModule({
@@ -1088,7 +1089,7 @@ describe('MatSelect', () => {
10881089

10891090
options[1].click();
10901091
fixture.detectChanges();
1091-
trigger.click();
1092+
fixture.componentInstance.select.open();
10921093
fixture.detectChanges();
10931094
flush();
10941095

@@ -1098,10 +1099,13 @@ describe('MatSelect', () => {
10981099

10991100
fixture.componentInstance.control.setValue(fixture.componentInstance.foods[7].value);
11001101
fixture.detectChanges();
1101-
trigger.click();
1102+
fixture.componentInstance.select.close();
11021103
fixture.detectChanges();
11031104
flush();
11041105

1106+
fixture.componentInstance.select.open();
1107+
fixture.detectChanges();
1108+
11051109
activeOptions = options.filter(option => option.classList.contains('mat-active'));
11061110
expect(activeOptions).toEqual([options[7]],
11071111
'Expected only selected option to be marked as active after the value has changed.');

0 commit comments

Comments
 (0)