@@ -5,6 +5,8 @@ import {createKeyboardEvent} from '@angular/cdk/testing';
5
5
import { Component , DebugElement } from '@angular/core' ;
6
6
import { async , ComponentFixture , TestBed } from '@angular/core/testing' ;
7
7
import { By } from '@angular/platform-browser' ;
8
+ import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
9
+ import { MatFormFieldModule } from '@angular/material/form-field' ;
8
10
import { MatChipInput , MatChipInputEvent } from './chip-input' ;
9
11
import { MatChipsModule } from './index' ;
10
12
import { MAT_CHIPS_DEFAULT_OPTIONS , MatChipsDefaultOptions } from './chip-default-options' ;
@@ -20,7 +22,7 @@ describe('MatChipInput', () => {
20
22
21
23
beforeEach ( async ( ( ) => {
22
24
TestBed . configureTestingModule ( {
23
- imports : [ MatChipsModule , PlatformModule ] ,
25
+ imports : [ PlatformModule , MatChipsModule , MatFormFieldModule , NoopAnimationsModule ] ,
24
26
declarations : [ TestChipInput ] ,
25
27
providers : [ {
26
28
provide : Directionality , useFactory : ( ) => {
@@ -64,6 +66,22 @@ describe('MatChipInput', () => {
64
66
65
67
expect ( inputNativeElement . getAttribute ( 'placeholder' ) ) . toBe ( 'bound placeholder' ) ;
66
68
} ) ;
69
+
70
+ it ( 'should propagate the dynamic `placeholder` value to the form field' , ( ) => {
71
+ fixture . componentInstance . placeholder = 'add a chip' ;
72
+ fixture . detectChanges ( ) ;
73
+
74
+ const label : HTMLElement = fixture . nativeElement . querySelector ( '.mat-form-field-label' ) ;
75
+
76
+ expect ( label ) . toBeTruthy ( ) ;
77
+ expect ( label . textContent ) . toContain ( 'add a chip' ) ;
78
+
79
+ fixture . componentInstance . placeholder = 'or don\'t' ;
80
+ fixture . detectChanges ( ) ;
81
+
82
+ expect ( label . textContent ) . toContain ( 'or don\'t' ) ;
83
+ } ) ;
84
+
67
85
} ) ;
68
86
69
87
describe ( '[addOnBlur]' , ( ) => {
@@ -117,7 +135,7 @@ describe('MatChipInput', () => {
117
135
TestBed
118
136
. resetTestingModule ( )
119
137
. configureTestingModule ( {
120
- imports : [ MatChipsModule , PlatformModule ] ,
138
+ imports : [ MatChipsModule , MatFormFieldModule , PlatformModule , NoopAnimationsModule ] ,
121
139
declarations : [ TestChipInput ] ,
122
140
providers : [ {
123
141
provide : MAT_CHIPS_DEFAULT_OPTIONS ,
@@ -146,12 +164,14 @@ describe('MatChipInput', () => {
146
164
147
165
@Component ( {
148
166
template : `
149
- <mat-chip-list #chipList>
150
- </mat-chip-list>
151
- <input matInput [matChipInputFor]="chipList"
152
- [matChipInputAddOnBlur]="addOnBlur"
153
- (matChipInputTokenEnd)="add($event)"
154
- [placeholder]="placeholder" />
167
+ <mat-form-field>
168
+ <mat-chip-list #chipList>
169
+ </mat-chip-list>
170
+ <input matInput [matChipInputFor]="chipList"
171
+ [matChipInputAddOnBlur]="addOnBlur"
172
+ (matChipInputTokenEnd)="add($event)"
173
+ [placeholder]="placeholder" />
174
+ </mat-form-field>
155
175
`
156
176
} )
157
177
class TestChipInput {
0 commit comments