|
1 | 1 | /* eslint-env browser */
|
2 |
| -import React, { Component } from 'react' |
| 2 | +import React, { Component, PureComponent } from 'react' |
3 | 3 | import createReactClass from 'create-react-class'
|
4 | 4 | import { mount } from 'enzyme'
|
5 | 5 | import { mapProps } from 'recompose'
|
@@ -519,6 +519,66 @@ describe(`AppContainer (dev)`, () => {
|
519 | 519 | expect(wrapper.text()).toBe('new render + old state')
|
520 | 520 | })
|
521 | 521 |
|
| 522 | + it('replaces PureComponent', () => { |
| 523 | + const spy = jest.fn() |
| 524 | + |
| 525 | + class Pure extends PureComponent { |
| 526 | + componentWillUnmount() { |
| 527 | + spy() |
| 528 | + } |
| 529 | + render() { |
| 530 | + return <span>I am old</span> |
| 531 | + } |
| 532 | + } |
| 533 | + |
| 534 | + RHL.register(Pure, 'Pure', 'test.js') |
| 535 | + |
| 536 | + class RenderFn extends PureComponent { |
| 537 | + render() { |
| 538 | + const { _children, v } = this.props |
| 539 | + return _children()(v) |
| 540 | + } |
| 541 | + } |
| 542 | + |
| 543 | + const innerRenderFn = v => <Pure v={v} /> |
| 544 | + const renderFn = () => innerRenderFn |
| 545 | + |
| 546 | + class App extends PureComponent { |
| 547 | + render() { |
| 548 | + return ( |
| 549 | + <div> |
| 550 | + <RenderFn value={42} _children={renderFn} /> |
| 551 | + </div> |
| 552 | + ) |
| 553 | + } |
| 554 | + } |
| 555 | + |
| 556 | + const wrapper = mount( |
| 557 | + <AppContainer> |
| 558 | + <App /> |
| 559 | + </AppContainer>, |
| 560 | + ) |
| 561 | + expect(wrapper.text()).toBe('I am old') |
| 562 | + |
| 563 | + { |
| 564 | + class Pure extends PureComponent { |
| 565 | + componentWillUnmount() { |
| 566 | + spy() |
| 567 | + } |
| 568 | + render() { |
| 569 | + return <span>I am new</span> |
| 570 | + } |
| 571 | + } |
| 572 | + |
| 573 | + RHL.register(Pure, 'Pure', 'test.js') |
| 574 | + |
| 575 | + wrapper.setProps({ children: <App /> }) |
| 576 | + } |
| 577 | + |
| 578 | + expect(wrapper.text()).toBe('I am new') |
| 579 | + expect(spy).not.toHaveBeenCalled() |
| 580 | + }) |
| 581 | + |
522 | 582 | it(
|
523 | 583 | 'replaces children with class property arrow ' +
|
524 | 584 | 'functions with different numbers of arguments',
|
|
0 commit comments