@@ -185,26 +185,14 @@ describe('MatTextareaAutosize', () => {
185
185
autosize = fixtureWithPlaceholder . debugElement . query (
186
186
By . directive ( MatTextareaAutosize ) ) . injector . get < MatTextareaAutosize > ( MatTextareaAutosize ) ;
187
187
188
- // To be able to trigger a new calculation of the height with a long placeholder, the textarea
189
- // value needs to be changed.
190
- textarea . value = '1' ;
191
- autosize . resizeToFitContent ( ) ;
192
-
193
- textarea . value = '' ;
194
- autosize . resizeToFitContent ( ) ;
188
+ triggerTextareaResize ( ) ;
195
189
196
190
const heightWithLongPlaceholder = textarea . clientHeight ;
197
191
198
192
fixtureWithPlaceholder . componentInstance . placeholder = 'Short' ;
199
193
fixtureWithPlaceholder . detectChanges ( ) ;
200
194
201
- // To be able to trigger a new calculation of the height with a short placeholder, the
202
- // textarea value needs to be changed.
203
- textarea . value = '1' ;
204
- autosize . resizeToFitContent ( ) ;
205
-
206
- textarea . value = '' ;
207
- autosize . resizeToFitContent ( ) ;
195
+ triggerTextareaResize ( ) ;
208
196
209
197
expect ( textarea . clientHeight ) . toBe ( heightWithLongPlaceholder ,
210
198
'Expected the textarea height to be the same with a long placeholder.' ) ;
@@ -261,8 +249,18 @@ describe('MatTextareaAutosize', () => {
261
249
textarea = fixtureWithForms . nativeElement . querySelector ( 'textarea' ) ;
262
250
expect ( textarea . getBoundingClientRect ( ) . height ) . toBeGreaterThan ( 1 ) ;
263
251
} ) ;
264
- } ) ;
265
252
253
+ /** Triggers a textarea resize to fit the content. */
254
+ function triggerTextareaResize ( ) {
255
+ // To be able to trigger a new calculation of the height with a short placeholder, the
256
+ // textarea value needs to be changed.
257
+ textarea . value = '1' ;
258
+ autosize . resizeToFitContent ( ) ;
259
+
260
+ textarea . value = '' ;
261
+ autosize . resizeToFitContent ( ) ;
262
+ }
263
+ } ) ;
266
264
267
265
// Styles to reset padding and border to make measurement comparisons easier.
268
266
const textareaStyleReset = `
0 commit comments