From 90cd663850e2bec39fb8c94e8381c3ad3c9cbe79 Mon Sep 17 00:00:00 2001 From: Anton Korzunov Date: Tue, 24 Apr 2018 19:50:40 +1000 Subject: [PATCH] Add PureComponent related tests. #944 --- 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',