@@ -485,16 +485,97 @@ describe('ReactDOMServerIntegration', () => {
485
485
expect ( e . tagName ) . toBe ( 'BUTTON' ) ;
486
486
} ) ;
487
487
488
- itRenders ( 'a div with dangerouslySetInnerHTML' , async render => {
489
- const e = await render (
490
- < div dangerouslySetInnerHTML = { { __html : "<span id='child'/>" } } /> ,
491
- ) ;
488
+ itRenders ( 'a div with dangerouslySetInnerHTML number' , async render => {
489
+ // Put dangerouslySetInnerHTML one level deeper because otherwise
490
+ // hydrating from a bad markup would cause a mismatch (since we don't
491
+ // patch dangerouslySetInnerHTML as text content).
492
+ const e = ( await render (
493
+ < div >
494
+ < span dangerouslySetInnerHTML = { { __html : 0 } } />
495
+ </ div > ,
496
+ ) ) . firstChild ;
497
+ expect ( e . childNodes . length ) . toBe ( 1 ) ;
498
+ expect ( e . firstChild . nodeType ) . toBe ( TEXT_NODE_TYPE ) ;
499
+ expect ( e . textContent ) . toBe ( '0' ) ;
500
+ } ) ;
501
+
502
+ itRenders ( 'a div with dangerouslySetInnerHTML boolean' , async render => {
503
+ // Put dangerouslySetInnerHTML one level deeper because otherwise
504
+ // hydrating from a bad markup would cause a mismatch (since we don't
505
+ // patch dangerouslySetInnerHTML as text content).
506
+ const e = ( await render (
507
+ < div >
508
+ < span dangerouslySetInnerHTML = { { __html : false } } />
509
+ </ div > ,
510
+ ) ) . firstChild ;
511
+ expect ( e . childNodes . length ) . toBe ( 1 ) ;
512
+ expect ( e . firstChild . nodeType ) . toBe ( TEXT_NODE_TYPE ) ;
513
+ expect ( e . firstChild . data ) . toBe ( 'false' ) ;
514
+ } ) ;
515
+
516
+ itRenders (
517
+ 'a div with dangerouslySetInnerHTML text string' ,
518
+ async render => {
519
+ // Put dangerouslySetInnerHTML one level deeper because otherwise
520
+ // hydrating from a bad markup would cause a mismatch (since we don't
521
+ // patch dangerouslySetInnerHTML as text content).
522
+ const e = ( await render (
523
+ < div >
524
+ < span dangerouslySetInnerHTML = { { __html : 'hello' } } />
525
+ </ div > ,
526
+ ) ) . firstChild ;
527
+ expect ( e . childNodes . length ) . toBe ( 1 ) ;
528
+ expect ( e . firstChild . nodeType ) . toBe ( TEXT_NODE_TYPE ) ;
529
+ expect ( e . textContent ) . toBe ( 'hello' ) ;
530
+ } ,
531
+ ) ;
532
+
533
+ itRenders (
534
+ 'a div with dangerouslySetInnerHTML element string' ,
535
+ async render => {
536
+ const e = await render (
537
+ < div dangerouslySetInnerHTML = { { __html : "<span id='child'/>" } } /> ,
538
+ ) ;
539
+ expect ( e . childNodes . length ) . toBe ( 1 ) ;
540
+ expect ( e . firstChild . tagName ) . toBe ( 'SPAN' ) ;
541
+ expect ( e . firstChild . getAttribute ( 'id' ) ) . toBe ( 'child' ) ;
542
+ expect ( e . firstChild . childNodes . length ) . toBe ( 0 ) ;
543
+ } ,
544
+ ) ;
545
+
546
+ itRenders ( 'a div with dangerouslySetInnerHTML object' , async render => {
547
+ const obj = {
548
+ toString ( ) {
549
+ return "<span id='child'/>" ;
550
+ } ,
551
+ } ;
552
+ const e = await render ( < div dangerouslySetInnerHTML = { { __html : obj } } /> ) ;
492
553
expect ( e . childNodes . length ) . toBe ( 1 ) ;
493
554
expect ( e . firstChild . tagName ) . toBe ( 'SPAN' ) ;
494
555
expect ( e . firstChild . getAttribute ( 'id' ) ) . toBe ( 'child' ) ;
495
556
expect ( e . firstChild . childNodes . length ) . toBe ( 0 ) ;
496
557
} ) ;
497
558
559
+ itRenders (
560
+ 'a div with dangerouslySetInnerHTML set to null' ,
561
+ async render => {
562
+ const e = await render (
563
+ < div dangerouslySetInnerHTML = { { __html : null } } /> ,
564
+ ) ;
565
+ expect ( e . childNodes . length ) . toBe ( 0 ) ;
566
+ } ,
567
+ ) ;
568
+
569
+ itRenders (
570
+ 'a div with dangerouslySetInnerHTML set to undefined' ,
571
+ async render => {
572
+ const e = await render (
573
+ < div dangerouslySetInnerHTML = { { __html : undefined } } /> ,
574
+ ) ;
575
+ expect ( e . childNodes . length ) . toBe ( 0 ) ;
576
+ } ,
577
+ ) ;
578
+
498
579
describe ( 'newline-eating elements' , function ( ) {
499
580
itRenders (
500
581
'a newline-eating tag with content not starting with \\n' ,
0 commit comments