88} = require ( 'react' ) ;
99const TestRenderer = require ( 'react-test-renderer' ) ;
1010const createMockComponentContext = require ( 'fluxible/utils/createMockComponentContext' ) ;
11- const { connectToStores, FluxibleComponent } = require ( '../../../' ) ;
11+ const { connectToStores, FluxibleProvider } = require ( '../../../' ) ;
1212const FooStore = require ( '../../fixtures/stores/FooStore' ) ;
1313const BarStore = require ( '../../fixtures/stores/BarStore' ) ;
1414
@@ -40,15 +40,18 @@ const renderComponent = (Component, ref) => {
4040 const context = createMockComponentContext ( { stores } ) ;
4141
4242 const app = TestRenderer . create (
43- < FluxibleComponent context = { context } >
43+ < FluxibleProvider context = { context } >
4444 < Component ref = { ref } />
45- </ FluxibleComponent >
45+ </ FluxibleProvider >
4646 ) ;
4747
4848 return { app, context } ;
4949} ;
5050
51- const getComponent = ( app ) => app . root . findByType ( DumbComponent ) ;
51+ const getComponent = ( app , component ) => app . root . findByType ( component ) ;
52+
53+ const getStoreConnector = ( app ) =>
54+ app . root . find ( ( node ) => node . type . name === 'StoreConnector' ) ;
5255
5356describe ( 'fluxible-addons-react' , ( ) => {
5457 describe ( 'connectToStores' , ( ) => {
@@ -80,7 +83,7 @@ describe('fluxible-addons-react', () => {
8083
8184 it ( 'should forward props from getStateFromStores to component' , ( ) => {
8285 const { app } = renderComponent ( ConnectedComponent ) ;
83- const component = getComponent ( app ) ;
86+ const component = getComponent ( app , DumbComponent ) ;
8487
8588 expect ( component . props . foo ) . toBe ( 'bar' ) ;
8689 expect ( component . props . bar ) . toBe ( 'baz' ) ;
@@ -89,7 +92,7 @@ describe('fluxible-addons-react', () => {
8992
9093 it ( 'should listen to store changes' , ( ) => {
9194 const { app } = renderComponent ( ConnectedComponent ) ;
92- const component = getComponent ( app ) ;
95+ const component = getComponent ( app , DumbComponent ) ;
9396
9497 component . props . onClick ( ) ;
9598
@@ -156,6 +159,30 @@ describe('fluxible-addons-react', () => {
156159 renderComponent ( ConnectedForwardComponent , ref2 ) ;
157160 expect ( ref2 . current . number ) . toBe ( 24 ) ;
158161 } ) ;
162+
163+ it ( 'does not pass fluxibleRef to StoreConnector if ref is disabled' , ( ) => {
164+ const ref = createRef ( null ) ;
165+ const { app } = renderComponent ( ConnectedComponent , ref ) ;
166+
167+ const connector = app . root . find (
168+ ( node ) => node . type . name === 'StoreConnector'
169+ ) ;
170+ expect ( connector . props . fluxibleRef ) . toBe ( undefined ) ;
171+
172+ const component = getComponent ( app , ConnectedComponent ) ;
173+ expect ( component . props . fluxibleRef ) . toBe ( undefined ) ;
174+ } ) ;
175+
176+ it ( 'does not leak fluxibleRef to inner component' , ( ) => {
177+ const ref = createRef ( null ) ;
178+ const { app } = renderComponent ( ConnectedClassComponent , ref ) ;
179+
180+ const connector = getStoreConnector ( app ) ;
181+ expect ( connector . props . fluxibleRef ) . not . toBe ( undefined ) ;
182+
183+ const component = getComponent ( app , ConnectedClassComponent ) ;
184+ expect ( component . props . fluxibleRef ) . toBe ( undefined ) ;
185+ } ) ;
159186 } ) ;
160187 } ) ;
161188} ) ;
0 commit comments