React Base Fiddle (JSX)

Starting point for creating JSFiddles with React. This uses React with Addons.

by Martoid Prime

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.js"></script>
<script src="https://fb.me/react-with-addons-0.14.6.js"></script>
<script src="https://fb.me/react-dom-0.14.6.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-bootstrap/0.28.3/react-bootstrap.min.js"></script>
<script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>

<div id="container" class="containerClass">
    <!-- This element's contents will be replaced with your component. -->
</div>

CSS

.containerClass {
  padding: 6px;
  background-color: lightblue;
  display: inline-block;
}

.my-modal-class {
  background-color: lightgreen;
}

JavaScript 1.7

var Modal = ReactBootstrap.Modal;
var Button = ReactBootstrap.Button;
var TestUtils = React.addons.TestUtils;

var MyModal = React.createClass({
  render: function() {
    return (
      <Modal className="my-modal-class" show={this.props.show}>
        <Modal.Header>
          <Modal.Title>My Modal</Modal.Title>
        </Modal.Header>
        <Modal.Body>
          Hello, World!
        </Modal.Body>
        <Modal.Footer>
          <Button onClick={this.props.onHide}>Close</Button>
        </Modal.Footer>
      </Modal>
    );
  }
});

var runTests = function RunTestsOnModal(){
		console.log("running tests");
		var spy = function(){console.log("spy hit!");};
    var MyModalComponent = TestUtils.renderIntoDocument(
      <MyModal show onHide={spy}/>
    );
		
    console.log("running findRenderedComponentWithType");
    // This passes
    TestUtils.findRenderedComponentWithType(MyModalComponent, MyModal);
    
    console.log("running alternative to findRenderedDOMComponentWithTag");
    var closeButton = document.body.getElementsByClassName("my-modal-class")[0].getElementsByClassName("btn btn-default")[0];

		console.log("running findRenderedDOMComponentWithTag");
    // This fails
    //var CloseButton = TestUtils.findRenderedDOMComponentWithTag(MyModalComponent, 'button');

		console.log("Simulate click");
    // Never gets here
    TestUtils.Simulate.click(closeButton);
    //expect(spy.calledOnce).to.be.true;
};

ReactDOM.render(
<div>
	<Button onClick={runTests}>Run Tests</Button>
</div>,
  document.getElementById('container')
);