Added a PureComponent contextType test (#13729)
Brian Vaughn committed
Sep 25, 2018 at 17:28 UTC
d0c0ec98ef1fdf0791aeca38a0fa857fe52d9845
1 file changed
+33
packages/react/src/__tests__/ReactContextValidator-test.js
+33
@@ -438,6 +438,39 @@ describe('ReactContextValidator', () => {
438
expect(shouldComponentUpdateWasCalled).toBe(false);
439
});
440
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
+
474
it('should warn if both contextType and contextTypes are defined', () => {
475
const Context = React.createContext();
476