@@ -29,6 +29,7 @@ describe('React', () => {
2929 let renderedItems : any [ ] = [ ]
3030 type RootState = ReturnType < typeof normalStore . getState >
3131 let useNormalSelector : TypedUseSelectorHook < RootState > = useSelector
32+ type VoidFunc = ( ) => void
3233
3334 beforeEach ( ( ) => {
3435 normalStore = createStore (
@@ -122,6 +123,21 @@ describe('React', () => {
122123 } )
123124
124125 it ( 'subscribes to the store synchronously' , ( ) => {
126+ const listeners = new Set < VoidFunc > ( )
127+ const originalSubscribe = normalStore . subscribe
128+
129+ jest
130+ . spyOn ( normalStore , 'subscribe' )
131+ . mockImplementation ( ( callback : VoidFunc ) => {
132+ listeners . add ( callback )
133+ const originalUnsubscribe = originalSubscribe ( callback )
134+
135+ return ( ) => {
136+ listeners . delete ( callback )
137+ originalUnsubscribe ( )
138+ }
139+ } )
140+
125141 let rootSubscription : Subscription
126142
127143 const Parent = ( ) => {
@@ -141,23 +157,35 @@ describe('React', () => {
141157 < Parent />
142158 </ ProviderMock >
143159 )
144- // @ts -ignore ts(2454)
145- expect ( rootSubscription . getListeners ( ) . get ( ) . length ) . toBe ( 1 )
160+ // Provider + 1 component
161+ expect ( listeners . size ) . toBe ( 2 )
146162
147163 rtl . act ( ( ) => {
148164 normalStore . dispatch ( { type : '' } )
149165 } )
150166
151- // @ts -ignore ts(2454)
152- expect ( rootSubscription . getListeners ( ) . get ( ) . length ) . toBe ( 2 )
167+ // Provider + 2 components
168+ expect ( listeners . size ) . toBe ( 3 )
153169 } )
154170
155171 it ( 'unsubscribes when the component is unmounted' , ( ) => {
156- let rootSubscription : Subscription
172+ const originalSubscribe = normalStore . subscribe
173+
174+ const listeners = new Set < VoidFunc > ( )
175+
176+ jest
177+ . spyOn ( normalStore , 'subscribe' )
178+ . mockImplementation ( ( callback : VoidFunc ) => {
179+ listeners . add ( callback )
180+ const originalUnsubscribe = originalSubscribe ( callback )
181+
182+ return ( ) => {
183+ listeners . delete ( callback )
184+ originalUnsubscribe ( )
185+ }
186+ } )
157187
158188 const Parent = ( ) => {
159- const { subscription } = useReduxContext ( ) as ReactReduxContextValue
160- rootSubscription = subscription
161189 const count = useNormalSelector ( ( s ) => s . count )
162190 return count === 0 ? < Child /> : null
163191 }
@@ -172,15 +200,15 @@ describe('React', () => {
172200 < Parent />
173201 </ ProviderMock >
174202 )
175- // @ts -ignore ts(2454)
176- expect ( rootSubscription . getListeners ( ) . get ( ) . length ) . toBe ( 2 )
203+ // Provider + 2 components
204+ expect ( listeners . size ) . toBe ( 3 )
177205
178206 rtl . act ( ( ) => {
179207 normalStore . dispatch ( { type : '' } )
180208 } )
181209
182- // @ts -ignore ts(2454)
183- expect ( rootSubscription . getListeners ( ) . get ( ) . length ) . toBe ( 1 )
210+ // Provider + 1 component
211+ expect ( listeners . size ) . toBe ( 2 )
184212 } )
185213
186214 it ( 'notices store updates between render and store subscription effect' , ( ) => {
@@ -556,7 +584,7 @@ describe('React', () => {
556584 spy . mockRestore ( )
557585 } )
558586
559- it ( 'allows dealing with stale props by putting a specific connected component above the hooks component' , ( ) => {
587+ it . skip ( 'allows dealing with stale props by putting a specific connected component above the hooks component' , ( ) => {
560588 const spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
561589
562590 const Parent = ( ) => {
0 commit comments