Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Components: Add test confirming that withFilters does not rerender #6135

Merged
merged 1 commit into from Apr 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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