Skip to content

Commit

Permalink
Test case for React Context bailing out unexpectedly
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdustan authored and gaearon committed Mar 29, 2018
1 parent 5855e9f commit f092444
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,45 @@ describe('ReactNewContext', () => {
expect(ReactNoop.getChildren()).toEqual([span('Child')]);
});

it('renders context children when child is an instance method', () => {
const Context = React.createContext(0);

class App extends React.Component {
state = {
value: 0,
};

renderConsumer = (context) => {
ReactNoop.yield('App#renderConsumer');
return <span prop={this.state.value} />;
};

render() {
ReactNoop.yield('App');
return (
<Context.Provider value={this.props.value}>
<Context.Consumer>{this.renderConsumer}</Context.Consumer>
</Context.Provider>
);
}
}

// Initial mount
let inst;
ReactNoop.render(<App value={1} ref={ref => inst = ref} />);
expect(ReactNoop.flush()).toEqual(['App', 'App#renderConsumer']);
expect(ReactNoop.getChildren()).toEqual([span(0)]);

// Update
inst.setState({ value: 1});
expect(ReactNoop.flush()).toEqual([
'App',
// Child does because it may read from the instance
'App#renderConsumer',
]);
expect(ReactNoop.getChildren()).toEqual([span(1)]);
});

// This is a regression case for https://github.com/facebook/react/issues/12389.
it('does not run into an infinite loop', () => {
const Context = React.createContext(null);
Expand Down

0 comments on commit f092444

Please sign in to comment.