From acb6bf1c14f774872413e1b26ac3bd744cc904cd Mon Sep 17 00:00:00 2001 From: Anton Date: Tue, 24 Apr 2018 22:51:34 +1000 Subject: [PATCH] tests: add PureComponent test #944 (#946) --- test/AppContainer.dev.test.js | 62 ++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/test/AppContainer.dev.test.js b/test/AppContainer.dev.test.js index 26ccd9f2a..2743332df 100644 --- a/test/AppContainer.dev.test.js +++ b/test/AppContainer.dev.test.js @@ -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' @@ -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 I am old + } + } + + RHL.register(Pure, 'Pure', 'test.js') + + class RenderFn extends PureComponent { + render() { + const { _children, v } = this.props + return _children()(v) + } + } + + const innerRenderFn = v => + const renderFn = () => innerRenderFn + + class App extends PureComponent { + render() { + return ( +
+ +
+ ) + } + } + + const wrapper = mount( + + + , + ) + expect(wrapper.text()).toBe('I am old') + + { + class Pure extends PureComponent { + componentWillUnmount() { + spy() + } + render() { + return I am new + } + } + + RHL.register(Pure, 'Pure', 'test.js') + + wrapper.setProps({ children: }) + } + + expect(wrapper.text()).toBe('I am new') + expect(spy).not.toHaveBeenCalled() + }) + it( 'replaces children with class property arrow ' + 'functions with different numbers of arguments',