Added a PureComponent contextType test (#13729)

This commit is contained in:
Brian Vaughn authored and GitHub committed 2018-09-25 17:28:33 -07:00
1 parent 4b68a6498b
commit d0c0ec98ef
1 file changed
+33
@@ -438,6 +438,39 @@ describe('ReactContextValidator', () => {
expect(shouldComponentUpdateWasCalled).toBe(false);
});
it('should re-render PureComponents when context Provider updates', () => {
let renderedContext;
const Context = React.createContext();
class Component extends React.PureComponent {
static contextType = Context;
render() {
renderedContext = this.context;
return <div />;
}
}
const firstContext = {foo: 123};
const secondContext = {bar: 456};
const container = document.createElement('div');
ReactDOM.render(
<Context.Provider value={firstContext}>
<Component />
</Context.Provider>,
container,
);
expect(renderedContext).toBe(firstContext);
ReactDOM.render(
<Context.Provider value={secondContext}>
<Component />
</Context.Provider>,
container,
);
expect(renderedContext).toBe(secondContext);
});
it('should warn if both contextType and contextTypes are defined', () => {
const Context = React.createContext();