Skip to content
This repository has been archived by the owner on Jul 19, 2019. It is now read-only.

Add test to make sure context propagates properly #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/__tests__/ReactART-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var React = require('react');
var ReactDOM = require('react-dom');
var ReactTestUtils = require('react-addons-test-utils');

var ClippingRectangle;
var Group;
var Shape;
var Surface;
Expand Down Expand Up @@ -56,6 +57,7 @@ describe('ReactART', function() {
beforeEach(function() {
ARTCurrentMode.setCurrent(ARTSVGMode);

ClippingRectangle = ReactART.ClippingRectangle;
Group = ReactART.Group;
Shape = ReactART.Shape;
Surface = ReactART.Surface;
Expand Down Expand Up @@ -286,4 +288,46 @@ describe('ReactART', function() {
expect(ref.constructor).toBe(CustomShape);
});

it('propagates context down through groups', function() {
var contextValue;
var innerExpects = 0;
var CustomShape = React.createClass({
contextTypes: {
value: React.PropTypes.number
},
render: function() {
expect(this.context.value).toBe(contextValue);
innerExpects++;
return <Shape />;
},
});
var Container = React.createClass({
childContextTypes: {
value: React.PropTypes.number
},
getChildContext: function() {
return {value: this.props.contextValue};
},
render: function() {
return (
<Surface>
<Group>
<ClippingRectangle>
<CustomShape />
{this.props.contextValue === 2 && <CustomShape />}
</ClippingRectangle>
</Group>
</Surface>
);
},
});

var container = document.createElement('div');
contextValue = 1;
ReactDOM.render(<Container contextValue={contextValue} />, container);
contextValue = 2;
ReactDOM.render(<Container contextValue={contextValue} />, container);
expect(innerExpects).toBe(3);
});

});