title: How do I write a test for a component that uses React.cloneElement?
body: <p>My top level component takes <code>children</code> from <code>react-router</code> like so:</p>
  
  <pre><code>class App extends Component {
    render() {
      return (
        &lt;div&gt;
           {React.cloneElement(children, this.props.widgets)}
        &lt;/div&gt;
      )
    }
  }
  </code></pre>
  
  <p>I'm trying to write a simple test with <code>jest</code>, like this:</p>
  
  <pre><code>it('renders without crashing', () =&gt; {
    const div = document.createElement('div')
    ReactDOM.render(&lt;App /&gt;, div)
  })
  </code></pre>
  
  <p>However, this test fails with the following error:</p>
  
  <pre><code> FAIL  src/App.test.js
    ● renders without crashing
  
      TypeError: Cannot read property 'props' of undefined
  
        at Object.&lt;anonymous&gt;.ReactElement.cloneElement (node_modules/react/lib/ReactElement.js:271:34)
        at Object.cloneElement (node_modules/react/lib/ReactElementValidator.js:216:48)
        at App.render (src/App.js:50:57)
        at node_modules/react-dom/lib/ReactCompositeComponent.js:796:21
        at measureLifeCyclePerf (node_modules/react-dom/lib/ReactCompositeComponent.js:75:12)
        at ReactCompositeComponentWrapper._renderValidatedComponentWithoutOwnerOrContext (node_modules/react-dom/lib/ReactCompositeComponent.js:795:25)
        at ReactCompositeComponentWrapper._renderValidatedComponent (node_modules/react-dom/lib/ReactCompositeComponent.js:822:32)
        at ReactCompositeComponentWrapper.performInitialMount (node_modules/react-dom/lib/ReactCompositeComponent.js:362:30)
        at ReactCompositeComponentWrapper.mountComponent (node_modules/react-dom/lib/ReactCompositeComponent.js:258:21)
        at Object.mountComponent (node_modules/react-dom/lib/ReactReconciler.js:46:35)
        at ReactCompositeComponentWrapper.performInitialMount (node_modules/react-dom/lib/ReactCompositeComponent.js:371:34)
        at ReactCompositeComponentWrapper.mountComponent (node_modules/react-dom/lib/ReactCompositeComponent.js:258:21)
        at Object.mountComponent (node_modules/react-dom/lib/ReactReconciler.js:46:35)
        at mountComponentIntoNode (node_modules/react-dom/lib/ReactMount.js:104:32)
        at ReactReconcileTransaction.perform (node_modules/react-dom/lib/Transaction.js:140:20)
        at batchedMountComponentIntoNode (node_modules/react-dom/lib/ReactMount.js:126:15)
        at ReactDefaultBatchingStrategyTransaction.perform (node_modules/react-dom/lib/Transaction.js:140:20)
        at Object.batchedUpdates (node_modules/react-dom/lib/ReactDefaultBatchingStrategy.js:62:26)
  </code></pre>
  
  <p>Is there a way to mock <code>cloneElement</code>? Or to test the component in such a way that it ignores the call to <code>cloneElement</code>?</p>