Skip to content

Commit d0c0ec9

Browse files
authored
Added a PureComponent contextType test (#13729)
1 parent 4b68a64 commit d0c0ec9

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

packages/react/src/__tests__/ReactContextValidator-test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,39 @@ describe('ReactContextValidator', () => {
438438
expect(shouldComponentUpdateWasCalled).toBe(false);
439439
});
440440

441+
it('should re-render PureComponents when context Provider updates', () => {
442+
let renderedContext;
443+
444+
const Context = React.createContext();
445+
446+
class Component extends React.PureComponent {
447+
static contextType = Context;
448+
render() {
449+
renderedContext = this.context;
450+
return <div />;
451+
}
452+
}
453+
454+
const firstContext = {foo: 123};
455+
const secondContext = {bar: 456};
456+
457+
const container = document.createElement('div');
458+
ReactDOM.render(
459+
<Context.Provider value={firstContext}>
460+
<Component />
461+
</Context.Provider>,
462+
container,
463+
);
464+
expect(renderedContext).toBe(firstContext);
465+
ReactDOM.render(
466+
<Context.Provider value={secondContext}>
467+
<Component />
468+
</Context.Provider>,
469+
container,
470+
);
471+
expect(renderedContext).toBe(secondContext);
472+
});
473+
441474
it('should warn if both contextType and contextTypes are defined', () => {
442475
const Context = React.createContext();
443476

0 commit comments

Comments
 (0)