diff --git a/packages/data/src/components/with-select/test/index.js b/packages/data/src/components/with-select/test/index.js index 4a874872df032d..b8cb523edfa004 100644 --- a/packages/data/src/components/with-select/test/index.js +++ b/packages/data/src/components/with-select/test/index.js @@ -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 @@ -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( () => {} ), + ] )( () =>
); + + const unsubscribe = jest.fn(); + const subscribe = jest.fn( () => unsubscribe ); + + renderToString( + + + + ); + + // 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,