@samitouri / QOS-React-2 / commits / 9a950e9a19

Added unit test to verify that context treats the component doing a render() as the parent.

Jim committed Apr 24, 2015 at 15:27 UTC 9a950e9a19437d1c113702dff7b174c103a89251
1 file changed +38 -1
src/core/__tests__/ReactCompositeComponent-test.js
+38 -1
@@ -485,7 +485,44 @@ describe('ReactCompositeComponent', function() {
485 );
486 });
487
488 - it('should pass context', function() {
488 + it('should pass context to children when not owner', function() {
489 + var Parent = React.createClass({
490 + render: function() {
491 + return <Child><Grandchild /></Child>;
492 + }
493 + });
494 +
495 + var Child = React.createClass({
496 + childContextTypes: {
497 + foo: ReactPropTypes.string
498 + },
499 +
500 + getChildContext: function() {
501 + return {
502 + foo: 'bar'
503 + };
504 + },
505 +
506 + render: function() {
507 + return React.Children.only(this.props.children);
508 + }
509 + });
510 +
511 + var Grandchild = React.createClass({
512 + contextTypes: {
513 + foo: ReactPropTypes.string
514 + },
515 +
516 + render: function() {
517 + return <div>{this.context.foo}</div>;
518 + },
519 + });
520 +
521 + var component = ReactTestUtils.renderIntoDocument(<Parent />);
522 + expect(React.findDOMNode(component).innerHTML).toBe('bar');
523 + });
524 +
525 + it('should pass context transitively', function() {
526 var childInstance = null;
527 var grandchildInstance = null;
528