1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @emails react-core
    
  8.  */
    
  9. 
    
  10. 'use strict';
    
  11. 
    
  12. // Requires
    
  13. let React;
    
  14. let ReactDOM;
    
  15. let ReactTestUtils;
    
  16. 
    
  17. // Test components
    
  18. let LowerLevelComposite;
    
  19. let MyCompositeComponent;
    
  20. 
    
  21. let expectSingleChildlessDiv;
    
  22. 
    
  23. /**
    
  24.  * Integration test, testing the combination of JSX with our unit of
    
  25.  * abstraction, `ReactCompositeComponent` does not ever add superfluous DOM
    
  26.  * nodes.
    
  27.  */
    
  28. describe('ReactCompositeComponentDOMMinimalism', () => {
    
  29.   beforeEach(() => {
    
  30.     React = require('react');
    
  31.     ReactDOM = require('react-dom');
    
  32.     ReactTestUtils = require('react-dom/test-utils');
    
  33. 
    
  34.     LowerLevelComposite = class extends React.Component {
    
  35.       render() {
    
  36.         return <div>{this.props.children}</div>;
    
  37.       }
    
  38.     };
    
  39. 
    
  40.     MyCompositeComponent = class extends React.Component {
    
  41.       render() {
    
  42.         return <LowerLevelComposite>{this.props.children}</LowerLevelComposite>;
    
  43.       }
    
  44.     };
    
  45. 
    
  46.     expectSingleChildlessDiv = function (instance) {
    
  47.       const el = ReactDOM.findDOMNode(instance);
    
  48.       expect(el.tagName).toBe('DIV');
    
  49.       expect(el.children.length).toBe(0);
    
  50.     };
    
  51.   });
    
  52. 
    
  53.   it('should not render extra nodes for non-interpolated text', () => {
    
  54.     let instance = <MyCompositeComponent>A string child</MyCompositeComponent>;
    
  55.     instance = ReactTestUtils.renderIntoDocument(instance);
    
  56.     expectSingleChildlessDiv(instance);
    
  57.   });
    
  58. 
    
  59.   it('should not render extra nodes for non-interpolated text', () => {
    
  60.     let instance = (
    
  61.       <MyCompositeComponent>{'Interpolated String Child'}</MyCompositeComponent>
    
  62.     );
    
  63.     instance = ReactTestUtils.renderIntoDocument(instance);
    
  64.     expectSingleChildlessDiv(instance);
    
  65.   });
    
  66. 
    
  67.   it('should not render extra nodes for non-interpolated text', () => {
    
  68.     let instance = (
    
  69.       <MyCompositeComponent>
    
  70.         <ul>This text causes no children in ul, just innerHTML</ul>
    
  71.       </MyCompositeComponent>
    
  72.     );
    
  73.     instance = ReactTestUtils.renderIntoDocument(instance);
    
  74.     const el = ReactDOM.findDOMNode(instance);
    
  75.     expect(el.tagName).toBe('DIV');
    
  76.     expect(el.children.length).toBe(1);
    
  77.     expect(el.children[0].tagName).toBe('UL');
    
  78.     expect(el.children[0].children.length).toBe(0);
    
  79.   });
    
  80. });