Skip to content

Commit

Permalink
tests: add PureComponent test #944 (#946)
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey authored and gregberge committed Apr 24, 2018
1 parent 9c406a8 commit acb6bf1
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion test/AppContainer.dev.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-env browser */
import React, { Component } from 'react'
import React, { Component, PureComponent } from 'react'
import createReactClass from 'create-react-class'
import { mount } from 'enzyme'
import { mapProps } from 'recompose'
Expand Down Expand Up @@ -519,6 +519,66 @@ describe(`AppContainer (dev)`, () => {
expect(wrapper.text()).toBe('new render + old state')
})

it('replaces PureComponent', () => {
const spy = jest.fn()

class Pure extends PureComponent {
componentWillUnmount() {
spy()
}
render() {
return <span>I am old</span>
}
}

RHL.register(Pure, 'Pure', 'test.js')

class RenderFn extends PureComponent {
render() {
const { _children, v } = this.props
return _children()(v)
}
}

const innerRenderFn = v => <Pure v={v} />
const renderFn = () => innerRenderFn

class App extends PureComponent {
render() {
return (
<div>
<RenderFn value={42} _children={renderFn} />
</div>
)
}
}

const wrapper = mount(
<AppContainer>
<App />
</AppContainer>,
)
expect(wrapper.text()).toBe('I am old')

{
class Pure extends PureComponent {
componentWillUnmount() {
spy()
}
render() {
return <span>I am new</span>
}
}

RHL.register(Pure, 'Pure', 'test.js')

wrapper.setProps({ children: <App /> })
}

expect(wrapper.text()).toBe('I am new')
expect(spy).not.toHaveBeenCalled()
})

it(
'replaces children with class property arrow ' +
'functions with different numbers of arguments',
Expand Down

0 comments on commit acb6bf1

Please sign in to comment.