Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions packages/element/src/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { shallow, mount } from 'enzyme';
import TestRenderer from 'react-test-renderer';

/**
* Internal dependencies
Expand All @@ -16,6 +17,7 @@ import {
RawHTML,
pure,
} from '../';
import { compose } from '../index';

describe( 'element', () => {
describe( 'renderToString', () => {
Expand Down Expand Up @@ -256,5 +258,51 @@ describe( 'element', () => {
wrapper.setState( { state: 'a' } ); // Keeping the same state value should not trigger a rerender
expect( wrapper.html() ).toBe( '<p>4</p>' );
} );

it( 'should not matter where pure is implemented via compose' +
' receiving a class component', () => {
let i = 0;
class MyComp extends Component {
constructor() {
super( ...arguments );
this.state = {};
}
render() {
return <p>{ ++i }</p>
}
}
const TestComp = compose([
pure,
createHigherOrderComponent(
( OriginalComponent ) => class extends Component {
constructor() {
super( ...arguments );
this.state = {
a:1
}
}
render() {
return <p>{ ++i }</p>
}
},
'withTest2'
),
] )( MyComp );
const element = TestRenderer.create( <TestComp /> );
//traverse tree to get the wrapped component instance
const wrappedComponent = element.root.find( node => node.instance !== null );
element.update(<TestComp />); // Updating with same props doesn't rerender
expect( element.toJSON().children[0] ).toBe( '1' );
element.update( <TestComp a /> ); // New prop should trigger a rerender
expect( element.toJSON().children[0] ).toBe( '2' );
element.update( <TestComp a /> ); // Keeping the same prop value should not rerender
expect( element.toJSON().children[0] ).toBe( '2' );
element.update( <TestComp b /> ); // Changing the prop value should rerender
expect( element.toJSON().children[0] ).toBe( '3' );
wrappedComponent.instance.setState( { a: 1 } ); // New state value should trigger a rerender
expect( element.toJSON().children[0] ).toBe( '4' );
wrappedComponent.instance.setState( { a: 1 } ); // Keeping the same state value should not trigger a rerender
expect( element.toJSON().children[0] ).toBe( '4' );
} );
} );
} );