mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Added a PureComponent contextType test (#13729)
This commit is contained in:
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();
|
||||
|
||||
|
||||
Reference in new issue
Block a user