Skip to content

Commit

Permalink
Components: Add test confirming that withFilters does not rerender (#…
Browse files Browse the repository at this point in the history
…6135)

It covers the case when filters added before the component was mounted.
  • Loading branch information
gziolo committed Apr 13, 2018
1 parent b29b92d commit e0342fa
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions components/higher-order/with-filters/test/index.js
Expand Up @@ -65,6 +65,31 @@ describe( 'withFilters', () => {
expect( wrapper.html() ).toBe( '<div><div>My component</div><div>Composed component</div></div>' );
} );

it( 'should not re-render component when new filter added before component was mounted', () => {
const spy = jest.fn();
const SpiedComponent = () => {
spy();
return <div>Spied component</div>;
};
addFilter(
hookName,
'test/enhanced-component-spy-1',
FilteredComponent => () => (
<blockquote>
<FilteredComponent />
</blockquote>
),
);
const EnhancedComponent = withFilters( hookName )( SpiedComponent );

wrapper = mount( <EnhancedComponent /> );

jest.runAllTimers();

expect( spy ).toHaveBeenCalledTimes( 1 );
expect( wrapper.html() ).toBe( '<blockquote><div>Spied component</div></blockquote>' );
} );

it( 'should re-render component once when new filter added after component was mounted', () => {
const spy = jest.fn();
const SpiedComponent = () => {
Expand Down

0 comments on commit e0342fa

Please sign in to comment.