title: How to test whether a React Component contains another component with jest?
body: <p>I'm trying to use jest-cli to test whether one react component contains another component in it's output. I'm having trouble figuring out how to do this.</p>
  
  <p>Here are my components:</p>
  
  <p><strong>DesignerPage Component</strong></p>
  
  <pre><code>[...]
  var TopBar = require('../components/layout/TopBar.js');
  
  var DesignerPage = React.createClass({
    getInitialState: function() {
      var state = {
      };
      return state;
    },
    render: function() {
      return (
        &lt;div&gt; 
          &lt;TopBar /&gt;
        &lt;/div&gt;
      )
    }
  });
  
  module.exports = DesignerPage;
  </code></pre>
  
  <p><strong>TopBar Component</strong></p>
  
  <pre><code>/** @jsx React.DOM */
  var React = require("react");
  
  var TopBar = React.createClass({
      render: function() {
          return (
              &lt;nav className="top-bar"&gt;
              &lt;/nav&gt;
          );
      }
  });
  
  module.exports = TopBar;
  </code></pre>
  
  <p>Now, I want to test whether the DesignerPage component contains the TopBar component. Here is what I think should work:</p>
  
  <pre><code>/** @jsx React.DOM */
  jest.dontMock('../../src/js/pages/DesignerPage.js');
  describe('DesignerPage', function() {
    it('should contain a TopBar', function() {
      var React = require('react/addons');
      var DesignerPage = require('../../src/js/pages/DesignerPage.js');
      var TestUtils = React.addons.TestUtils;
  
      // Render a DesignerPage into the document
      var page = TestUtils.renderIntoDocument(
        &lt;DesignerPage /&gt;
      );
  
      // Verify that a TopBar is included
      var topbar = TestUtils.scryRenderedComponentsWithType(page, 'TopBar');
      expect(topbar.length).toBe(1);
    });
  });
  </code></pre>
  
  <p>But it doesn't pass... :(</p>
  
  <pre><code>$ ./node_modules/jest-cli/bin/jest.js DesignerPage
  Found 1 matching test...
   FAIL  __tests__/pages/DesignerPage-test.js (4.175s)
  ● DesignerPage › it should contain a TopBar
    - Expected: 0 toBe: 1
          at Spec.&lt;anonymous&gt; (__tests__/pages/DesignerPage-test.js:16:27)
          at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)
  1 test failed, 0 test passed (1 total)
  Run time: 6.462s
  </code></pre>