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

Data: Avoid lingering listeners from stringified data-bound components #11819

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 30 additions & 1 deletion packages/data/src/components/with-select/test/index.js
Expand Up @@ -7,7 +7,7 @@ import TestRenderer from 'react-test-renderer';
* WordPress dependencies
*/
import { compose } from '@wordpress/compose';
import { Component } from '@wordpress/element';
import { Component, renderToString } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -300,6 +300,35 @@ describe( 'withSelect', () => {
expect( OriginalComponent ).toHaveBeenCalledTimes( 1 );
} );

it( 'should not leave lingering listeners if rendered to string', () => {
registry.registerStore( 'demo', {
reducer: () => ( {} ),
selectors: {
getState: ( state ) => state,
},
actions: {
update: () => ( { type: 'update' } ),
},
} );

const DataBoundComponent = compose( [
withSelect( () => {} ),
] )( () => <div /> );

const unsubscribe = jest.fn();
const subscribe = jest.fn( () => unsubscribe );

renderToString(
<RegistryProvider value={ { ...registry, subscribe } }>
<DataBoundComponent />
</RegistryProvider>
);

// A case could be made to enforce that no subscriptions were made. For
// the purposes of the test, at least ensure there are none lingering.
expect( subscribe.mock.calls ).toHaveLength( unsubscribe.mock.calls.length );
} );

it( 'should render if props have changed but not state', () => {
registry.registerStore( 'unchanging', {
reducer: ( state = {} ) => state,
Expand Down