Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a PureComponent contextType test #13729

Merged
merged 1 commit into from Sep 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions packages/react/src/__tests__/ReactContextValidator-test.js
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