@@ -24,8 +24,10 @@ describe('text-area', () => {
2424 } ) ;
2525
2626 describe ( 'native' , ( ) => {
27- function assertAttrCanBeSet ( prop , value ) {
27+ async function assertAttrCanBeSet ( prop , value ) {
2828 textArea [ prop ] = value ;
29+ await nextFrame ( ) ;
30+
2931 const attrValue = native . getAttribute ( prop ) ;
3032
3133 if ( value === true ) {
@@ -37,54 +39,53 @@ describe('text-area', () => {
3739 }
3840 }
3941
40- function assertPropCanBeSet ( prop , value ) {
41- for ( let i = 0 ; i < 3 ; i ++ ) {
42- // Check different values
43- const newValue = typeof value === 'boolean' ? i % 2 === 0 : value + i ;
44- textArea [ prop ] = newValue ;
45- expect ( native [ prop ] ) . to . be . equal ( newValue ) ;
46- }
47- }
48-
4942 [ 'placeholder' , 'value' ] . forEach ( ( prop ) => {
50- it ( `should set string property ${ prop } ` , ( ) => {
51- assertPropCanBeSet ( prop , 'foo' ) ;
43+ it ( `should set string property ${ prop } ` , async ( ) => {
44+ textArea [ prop ] = 'foo' ;
45+ await nextFrame ( ) ;
46+ expect ( native [ prop ] ) . to . be . equal ( 'foo' ) ;
5247 } ) ;
5348 } ) ;
5449
5550 [ 'disabled' ] . forEach ( ( prop ) => {
56- it ( `should set boolean property ${ prop } ` , ( ) => {
57- assertPropCanBeSet ( prop , true ) ;
51+ it ( `should set boolean property ${ prop } ` , async ( ) => {
52+ textArea [ prop ] = true ;
53+ await nextFrame ( ) ;
54+ expect ( native [ prop ] ) . to . be . true ;
55+
56+ textArea [ prop ] = false ;
57+ await nextFrame ( ) ;
58+ expect ( native [ prop ] ) . to . be . false ;
5859 } ) ;
5960 } ) ;
6061
6162 [ 'maxlength' , 'minlength' ] . forEach ( ( prop ) => {
62- it ( `should set numeric attribute ${ prop } ` , ( ) => {
63- assertAttrCanBeSet ( prop , 2 ) ;
63+ it ( `should set numeric attribute ${ prop } ` , async ( ) => {
64+ await assertAttrCanBeSet ( prop , 2 ) ;
6465 } ) ;
6566 } ) ;
6667
6768 [ 'autocomplete' ] . forEach ( ( prop ) => {
68- it ( `should set boolean attribute ${ prop } ` , ( ) => {
69- assertAttrCanBeSet ( prop , 'on' ) ;
69+ it ( `should set boolean attribute ${ prop } ` , async ( ) => {
70+ await assertAttrCanBeSet ( prop , 'on' ) ;
7071 } ) ;
7172 } ) ;
7273
7374 [ 'autocapitalize' ] . forEach ( ( prop ) => {
74- it ( `should set boolean attribute ${ prop } ` , ( ) => {
75- assertAttrCanBeSet ( prop , 'none' ) ;
75+ it ( `should set boolean attribute ${ prop } ` , async ( ) => {
76+ await assertAttrCanBeSet ( prop , 'none' ) ;
7677 } ) ;
7778 } ) ;
7879
7980 [ 'autocomplete' , 'autocorrect' , 'readonly' , 'required' ] . forEach ( ( prop ) => {
80- it ( `should set boolean attribute ${ prop } ` , ( ) => {
81- assertAttrCanBeSet ( prop , true ) ;
82- assertAttrCanBeSet ( prop , false ) ;
81+ it ( `should set boolean attribute ${ prop } ` , async ( ) => {
82+ await assertAttrCanBeSet ( prop , true ) ;
83+ await assertAttrCanBeSet ( prop , false ) ;
8384 } ) ;
8485 } ) ;
8586 } ) ;
8687
87- describe ( 'binding ' , ( ) => {
88+ describe ( 'value ' , ( ) => {
8889 it ( 'should set default value to empty string' , ( ) => {
8990 expect ( textArea . value ) . to . be . equal ( '' ) ;
9091 } ) ;
@@ -94,29 +95,34 @@ describe('text-area', () => {
9495 expect ( textArea . value ) . to . be . equal ( 'foo' ) ;
9596 } ) ;
9697
97- it ( 'should update has-value attribute when value is set' , ( ) => {
98+ it ( 'should update has-value attribute when value is set' , async ( ) => {
9899 textArea . value = 'foo' ;
100+ await nextFrame ( ) ;
99101 expect ( textArea . hasAttribute ( 'has-value' ) ) . to . be . true ;
100102 } ) ;
101103
102- it ( 'should not update has-value attribute when value is set to undefined' , ( ) => {
104+ it ( 'should not update has-value attribute when value is set to undefined' , async ( ) => {
103105 textArea . value = undefined ;
106+ await nextFrame ( ) ;
104107 expect ( textArea . hasAttribute ( 'has-value' ) ) . to . be . false ;
105108 } ) ;
106109
107- it ( 'should not update has-value attribute when value is set to empty string' , ( ) => {
110+ it ( 'should not update has-value attribute when value is set to empty string' , async ( ) => {
108111 textArea . value = '' ;
112+ await nextFrame ( ) ;
109113 expect ( textArea . hasAttribute ( 'has-value' ) ) . to . be . false ;
110114 } ) ;
111115
112116 // User could accidentally set a 0 or false value
113- it ( 'should update has-value attribute when numeric value is set' , ( ) => {
117+ it ( 'should update has-value attribute when numeric value is set' , async ( ) => {
114118 textArea . value = 0 ;
119+ await nextFrame ( ) ;
115120 expect ( textArea . hasAttribute ( 'has-value' ) ) . to . be . true ;
116121 } ) ;
117122
118- it ( 'should update has-value attribute when boolean value is set' , ( ) => {
123+ it ( 'should update has-value attribute when boolean value is set' , async ( ) => {
119124 textArea . value = false ;
125+ await nextFrame ( ) ;
120126 expect ( textArea . hasAttribute ( 'has-value' ) ) . to . be . true ;
121127 } ) ;
122128 } ) ;
@@ -151,17 +157,18 @@ describe('text-area', () => {
151157 container = textArea . shadowRoot . querySelector ( '.vaadin-text-area-container' ) ;
152158 } ) ;
153159
154- it ( 'should grow height with unwrapped text' , ( ) => {
160+ it ( 'should grow height with unwrapped text' , async ( ) => {
155161 const originalHeight = parseInt ( window . getComputedStyle ( inputField ) . height ) ;
156162
157163 // Make sure there are enough characters to grow the textarea
158164 textArea . value = Array ( 400 ) . join ( '400' ) ;
165+ await nextFrame ( ) ;
159166
160167 const newHeight = parseInt ( window . getComputedStyle ( inputField ) . height ) ;
161168 expect ( newHeight ) . to . be . at . least ( originalHeight + 10 ) ;
162169 } ) ;
163170
164- it ( 'should not grow over max-height' , ( ) => {
171+ it ( 'should not grow over max-height' , async ( ) => {
165172 inputField . style . padding = '0' ;
166173 inputField . style . border = 'none' ;
167174 textArea . style . maxHeight = '100px' ;
@@ -174,13 +181,14 @@ describe('text-area', () => {
174181 lot
175182 of
176183 rows` ;
184+ await nextFrame ( ) ;
177185
178186 expect ( parseFloat ( window . getComputedStyle ( textArea ) . height ) ) . to . be . lte ( 100 ) ;
179187 expect ( parseFloat ( window . getComputedStyle ( container ) . height ) ) . to . be . lte ( 100 ) ;
180188 expect ( parseFloat ( window . getComputedStyle ( inputField ) . height ) ) . to . be . lte ( 100 ) ;
181189 } ) ;
182190
183- it ( 'should not shrink less than min-height' , ( ) => {
191+ it ( 'should not shrink less than min-height' , async ( ) => {
184192 textArea . style . minHeight = '125px' ;
185193
186194 expect ( window . getComputedStyle ( textArea ) . height ) . to . be . equal ( '125px' ) ;
@@ -189,13 +197,14 @@ describe('text-area', () => {
189197
190198 // Check that value modification doesn't break min-height rule
191199 textArea . value = '1 row' ;
200+ await nextFrame ( ) ;
192201
193202 expect ( window . getComputedStyle ( textArea ) . height ) . to . be . equal ( '125px' ) ;
194203 expect ( window . getComputedStyle ( container ) . height ) . to . be . equal ( '125px' ) ;
195204 expect ( parseFloat ( window . getComputedStyle ( inputField ) . height ) ) . to . be . above ( 100 ) ;
196205 } ) ;
197206
198- it ( 'should stay between min and max height' , ( ) => {
207+ it ( 'should stay between min and max height' , async ( ) => {
199208 textArea . style . minHeight = '100px' ;
200209 textArea . style . maxHeight = '175px' ;
201210
@@ -216,30 +225,40 @@ describe('text-area', () => {
216225 and
217226 even
218227 more` ;
228+ await nextFrame ( ) ;
219229
220230 expect ( window . getComputedStyle ( textArea ) . height ) . to . be . equal ( '175px' ) ;
221231 expect ( window . getComputedStyle ( container ) . height ) . to . be . equal ( '175px' ) ;
222232 expect ( parseFloat ( window . getComputedStyle ( inputField ) . height ) ) . to . be . above ( 150 ) ;
223233 } ) ;
224234
225- it ( 'should increase inputField height' , ( ) => {
235+ it ( 'should increase input container height' , async ( ) => {
226236 textArea . style . height = '200px' ;
227237 textArea . value = 'foo' ;
238+ await nextFrame ( ) ;
228239 expect ( inputField . clientHeight ) . to . be . closeTo ( 200 , 10 ) ;
229240 } ) ;
230241
231- it ( 'should maintain scroll top' , ( ) => {
242+ it ( 'should maintain scroll top' , async ( ) => {
232243 textArea . style . maxHeight = '100px' ;
233244 textArea . value = Array ( 400 ) . join ( '400' ) ;
245+ await nextFrame ( ) ;
246+
234247 inputField . scrollTop = 200 ;
235248 textArea . value += 'foo' ;
249+ await nextFrame ( ) ;
250+
236251 expect ( inputField . scrollTop ) . to . equal ( 200 ) ;
237252 } ) ;
238253
239- it ( 'should decrease height automatically' , ( ) => {
254+ it ( 'should decrease height automatically' , async ( ) => {
240255 textArea . value = Array ( 400 ) . join ( '400' ) ;
256+ await nextFrame ( ) ;
257+
241258 const height = textArea . clientHeight ;
242259 textArea . value = '' ;
260+ await nextFrame ( ) ;
261+
243262 expect ( textArea . clientHeight ) . to . be . below ( height ) ;
244263 } ) ;
245264
@@ -271,21 +290,26 @@ describe('text-area', () => {
271290 ) ;
272291 } ) ;
273292
274- it ( 'should have matching height' , ( ) => {
293+ it ( 'should have matching height' , async ( ) => {
275294 inputField . style . padding = '0' ;
276295 textArea . style . maxHeight = '100px' ;
277296
278297 textArea . value = Array ( 400 ) . join ( '400' ) ;
298+ await nextFrame ( ) ;
299+
279300 textArea . value = textArea . value . slice ( 0 , - 1 ) ;
301+ await nextFrame ( ) ;
280302 expect ( native . clientHeight ) . to . equal ( inputField . scrollHeight ) ;
281303 } ) ;
282304
283- it ( 'should cover native field' , ( ) => {
305+ it ( 'should cover native textarea' , async ( ) => {
284306 inputField . style . padding = '0' ;
285307 inputField . style . border = 'none' ;
286308 textArea . style . minHeight = '300px' ;
287309 textArea . style . padding = '0' ;
310+
288311 textArea . value = 'foo' ;
312+ await nextFrame ( ) ;
289313
290314 expect ( native . clientHeight ) . to . equal (
291315 Math . round (
@@ -315,9 +339,10 @@ describe('text-area', () => {
315339 . style . getPropertyValue ( '--_text-area-vertical-scroll-position' ) ;
316340 }
317341
318- beforeEach ( ( ) => {
342+ beforeEach ( async ( ) => {
319343 textArea . style . height = '100px' ;
320344 textArea . value = 'a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz' ;
345+ await nextFrame ( ) ;
321346 } ) ;
322347
323348 it ( 'should be 0 initially' , ( ) => {
0 commit comments