Skip to content

Commit

Permalink
Added a PureComponent contextType test (#13729)
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaughn authored Sep 26, 2018
1 parent 4b68a64 commit d0c0ec9
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/react/src/__tests__/ReactContextValidator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit d0c0ec9

Please sign in to comment.