@@ -185,26 +185,14 @@ describe('MatTextareaAutosize', () => {
185185 autosize = fixtureWithPlaceholder . debugElement . query (
186186 By . directive ( MatTextareaAutosize ) ) . injector . get < MatTextareaAutosize > ( MatTextareaAutosize ) ;
187187
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 ( ) ;
195189
196190 const heightWithLongPlaceholder = textarea . clientHeight ;
197191
198192 fixtureWithPlaceholder . componentInstance . placeholder = 'Short' ;
199193 fixtureWithPlaceholder . detectChanges ( ) ;
200194
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 ( ) ;
208196
209197 expect ( textarea . clientHeight ) . toBe ( heightWithLongPlaceholder ,
210198 'Expected the textarea height to be the same with a long placeholder.' ) ;
@@ -261,8 +249,18 @@ describe('MatTextareaAutosize', () => {
261249 textarea = fixtureWithForms . nativeElement . querySelector ( 'textarea' ) ;
262250 expect ( textarea . getBoundingClientRect ( ) . height ) . toBeGreaterThan ( 1 ) ;
263251 } ) ;
264- } ) ;
265252
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+ } ) ;
266264
267265// Styles to reset padding and border to make measurement comparisons easier.
268266const textareaStyleReset = `
0 commit comments