@@ -19,6 +19,8 @@ describe('ReactDOMTextarea', () => {
19
19
20
20
let renderTextarea ;
21
21
22
+ const ReactFeatureFlags = require ( 'shared/ReactFeatureFlags' ) ;
23
+
22
24
beforeEach ( ( ) => {
23
25
jest . resetModules ( ) ;
24
26
@@ -287,23 +289,58 @@ describe('ReactDOMTextarea', () => {
287
289
}
288
290
} ) ;
289
291
290
- it ( 'should treat children like `defaultValue`' , ( ) => {
291
- const container = document . createElement ( 'div' ) ;
292
- let stub = < textarea > giraffe</ textarea > ;
293
- let node ;
292
+ if ( ReactFeatureFlags . disableTextareaChildren ) {
293
+ it ( 'should ignore children content' , ( ) => {
294
+ const container = document . createElement ( 'div' ) ;
295
+ let stub = < textarea > giraffe</ textarea > ;
296
+ let node ;
294
297
295
- expect ( ( ) => {
296
- node = renderTextarea ( stub , container ) ;
297
- } ) . toErrorDev (
298
- 'Use the `defaultValue` or `value` props instead of setting children on <textarea>.' ,
299
- ) ;
298
+ expect ( ( ) => {
299
+ node = renderTextarea ( stub , container ) ;
300
+ } ) . toErrorDev (
301
+ 'Use the `defaultValue` or `value` props instead of setting children on <textarea>.' ,
302
+ ) ;
303
+ expect ( node . value ) . toBe ( '' ) ;
304
+ // Changing children should do nothing, it functions like `defaultValue`.
305
+ stub = ReactDOM . render ( < textarea > gorilla</ textarea > , container ) ;
306
+ expect ( node . value ) . toEqual ( '' ) ;
307
+ } ) ;
308
+ }
300
309
301
- expect ( node . value ) . toBe ( 'giraffe' ) ;
310
+ if ( ReactFeatureFlags . disableTextareaChildren ) {
311
+ it ( 'should receive defaultValue and still ignore children content' , ( ) => {
312
+ let node ;
302
313
303
- // Changing children should do nothing, it functions like `defaultValue`.
304
- stub = ReactDOM . render ( < textarea > gorilla</ textarea > , container ) ;
305
- expect ( node . value ) . toEqual ( 'giraffe' ) ;
306
- } ) ;
314
+ expect ( ( ) => {
315
+ node = renderTextarea (
316
+ < textarea defaultValue = "dragon" > monkey</ textarea > ,
317
+ ) ;
318
+ } ) . toErrorDev (
319
+ 'Use the `defaultValue` or `value` props instead of setting children on <textarea>.' ,
320
+ ) ;
321
+ expect ( node . value ) . toBe ( 'dragon' ) ;
322
+ } ) ;
323
+ }
324
+
325
+ if ( ! ReactFeatureFlags . disableTextareaChildren ) {
326
+ it ( 'should treat children like `defaultValue`' , ( ) => {
327
+ const container = document . createElement ( 'div' ) ;
328
+ let stub = < textarea > giraffe</ textarea > ;
329
+ let node ;
330
+
331
+ expect ( ( ) => {
332
+ node = renderTextarea ( stub , container ) ;
333
+ } ) . toErrorDev (
334
+ 'Use the `defaultValue` or `value` props instead of setting children on <textarea>.' ,
335
+ ) ;
336
+
337
+ expect ( node . value ) . toBe ( 'giraffe' ) ;
338
+
339
+ // Changing children should do nothing, it functions like `defaultValue`.
340
+ stub = ReactDOM . render ( < textarea > gorilla</ textarea > , container ) ;
341
+ expect ( node . value ) . toEqual ( 'giraffe' ) ;
342
+ } ) ;
343
+ }
307
344
308
345
it ( 'should keep value when switching to uncontrolled element if not changed' , ( ) => {
309
346
const container = document . createElement ( 'div' ) ;
@@ -342,71 +379,120 @@ describe('ReactDOMTextarea', () => {
342
379
expect ( node . value ) . toEqual ( 'puppies' ) ;
343
380
} ) ;
344
381
345
- it ( 'should allow numbers as children' , ( ) => {
346
- let node ;
347
- expect ( ( ) => {
348
- node = renderTextarea ( < textarea > { 17 } </ textarea > ) ;
349
- } ) . toErrorDev (
350
- 'Use the `defaultValue` or `value` props instead of setting children on <textarea>.' ,
351
- ) ;
352
- expect ( node . value ) . toBe ( '17' ) ;
353
- } ) ;
354
-
355
- it ( 'should allow booleans as children' , ( ) => {
356
- let node ;
357
- expect ( ( ) => {
358
- node = renderTextarea ( < textarea > { false } </ textarea > ) ;
359
- } ) . toErrorDev (
360
- 'Use the `defaultValue` or `value` props instead of setting children on <textarea>.' ,
361
- ) ;
362
- expect ( node . value ) . toBe ( 'false' ) ;
363
- } ) ;
364
-
365
- it ( 'should allow objects as children' , ( ) => {
366
- const obj = {
367
- toString : function ( ) {
368
- return 'sharkswithlasers' ;
369
- } ,
370
- } ;
371
- let node ;
372
- expect ( ( ) => {
373
- node = renderTextarea ( < textarea > { obj } </ textarea > ) ;
374
- } ) . toErrorDev (
375
- 'Use the `defaultValue` or `value` props instead of setting children on <textarea>.' ,
376
- ) ;
377
- expect ( node . value ) . toBe ( 'sharkswithlasers' ) ;
378
- } ) ;
379
-
380
- it ( 'should throw with multiple or invalid children' , ( ) => {
381
- expect ( ( ) => {
382
- expect ( ( ) =>
383
- ReactTestUtils . renderIntoDocument (
384
- < textarea >
385
- { 'hello' }
386
- { 'there' }
387
- </ textarea > ,
388
- ) ,
389
- ) . toThrow ( '<textarea> can only have at most one child' ) ;
390
- } ) . toErrorDev (
391
- 'Use the `defaultValue` or `value` props instead of setting children on <textarea>.' ,
392
- ) ;
382
+ if ( ReactFeatureFlags . disableTextareaChildren ) {
383
+ it ( 'should ignore numbers as children' , ( ) => {
384
+ let node ;
385
+ expect ( ( ) => {
386
+ node = renderTextarea ( < textarea > { 17 } </ textarea > ) ;
387
+ } ) . toErrorDev (
388
+ 'Use the `defaultValue` or `value` props instead of setting children on <textarea>.' ,
389
+ ) ;
390
+ expect ( node . value ) . toBe ( '' ) ;
391
+ } ) ;
392
+ }
393
+
394
+ if ( ! ReactFeatureFlags . disableTextareaChildren ) {
395
+ it ( 'should allow numbers as children' , ( ) => {
396
+ let node ;
397
+ expect ( ( ) => {
398
+ node = renderTextarea ( < textarea > { 17 } </ textarea > ) ;
399
+ } ) . toErrorDev (
400
+ 'Use the `defaultValue` or `value` props instead of setting children on <textarea>.' ,
401
+ ) ;
402
+ expect ( node . value ) . toBe ( '17' ) ;
403
+ } ) ;
404
+ }
405
+
406
+ if ( ReactFeatureFlags . disableTextareaChildren ) {
407
+ it ( 'should ignore booleans as children' , ( ) => {
408
+ let node ;
409
+ expect ( ( ) => {
410
+ node = renderTextarea ( < textarea > { false } </ textarea > ) ;
411
+ } ) . toErrorDev (
412
+ 'Use the `defaultValue` or `value` props instead of setting children on <textarea>.' ,
413
+ ) ;
414
+ expect ( node . value ) . toBe ( '' ) ;
415
+ } ) ;
416
+ }
417
+
418
+ if ( ! ReactFeatureFlags . disableTextareaChildren ) {
419
+ it ( 'should allow booleans as children' , ( ) => {
420
+ let node ;
421
+ expect ( ( ) => {
422
+ node = renderTextarea ( < textarea > { false } </ textarea > ) ;
423
+ } ) . toErrorDev (
424
+ 'Use the `defaultValue` or `value` props instead of setting children on <textarea>.' ,
425
+ ) ;
426
+ expect ( node . value ) . toBe ( 'false' ) ;
427
+ } ) ;
428
+ }
429
+
430
+ if ( ReactFeatureFlags . disableTextareaChildren ) {
431
+ it ( 'should ignore objects as children' , ( ) => {
432
+ const obj = {
433
+ toString : function ( ) {
434
+ return 'sharkswithlasers' ;
435
+ } ,
436
+ } ;
437
+ let node ;
438
+ expect ( ( ) => {
439
+ node = renderTextarea ( < textarea > { obj } </ textarea > ) ;
440
+ } ) . toErrorDev (
441
+ 'Use the `defaultValue` or `value` props instead of setting children on <textarea>.' ,
442
+ ) ;
443
+ expect ( node . value ) . toBe ( '' ) ;
444
+ } ) ;
445
+ }
446
+
447
+ if ( ! ReactFeatureFlags . disableTextareaChildren ) {
448
+ it ( 'should allow objects as children' , ( ) => {
449
+ const obj = {
450
+ toString : function ( ) {
451
+ return 'sharkswithlasers' ;
452
+ } ,
453
+ } ;
454
+ let node ;
455
+ expect ( ( ) => {
456
+ node = renderTextarea ( < textarea > { obj } </ textarea > ) ;
457
+ } ) . toErrorDev (
458
+ 'Use the `defaultValue` or `value` props instead of setting children on <textarea>.' ,
459
+ ) ;
460
+ expect ( node . value ) . toBe ( 'sharkswithlasers' ) ;
461
+ } ) ;
462
+ }
393
463
394
- let node ;
395
- expect ( ( ) => {
396
- expect (
397
- ( ) =>
398
- ( node = renderTextarea (
464
+ if ( ! ReactFeatureFlags . disableTextareaChildren ) {
465
+ it ( 'should throw with multiple or invalid children' , ( ) => {
466
+ expect ( ( ) => {
467
+ expect ( ( ) =>
468
+ ReactTestUtils . renderIntoDocument (
399
469
< textarea >
400
- < strong />
470
+ { 'hello' }
471
+ { 'there' }
401
472
</ textarea > ,
402
- ) ) ,
403
- ) . not . toThrow ( ) ;
404
- } ) . toErrorDev (
405
- 'Use the `defaultValue` or `value` props instead of setting children on <textarea>.' ,
406
- ) ;
473
+ ) ,
474
+ ) . toThrow ( '<textarea> can only have at most one child' ) ;
475
+ } ) . toErrorDev (
476
+ 'Use the `defaultValue` or `value` props instead of setting children on <textarea>.' ,
477
+ ) ;
407
478
408
- expect ( node . value ) . toBe ( '[object Object]' ) ;
409
- } ) ;
479
+ let node ;
480
+ expect ( ( ) => {
481
+ expect (
482
+ ( ) =>
483
+ ( node = renderTextarea (
484
+ < textarea >
485
+ < strong />
486
+ </ textarea > ,
487
+ ) ) ,
488
+ ) . not . toThrow ( ) ;
489
+ } ) . toErrorDev (
490
+ 'Use the `defaultValue` or `value` props instead of setting children on <textarea>.' ,
491
+ ) ;
492
+
493
+ expect ( node . value ) . toBe ( '[object Object]' ) ;
494
+ } ) ;
495
+ }
410
496
411
497
it ( 'should unmount' , ( ) => {
412
498
const container = document . createElement ( 'div' ) ;
0 commit comments