@@ -2,7 +2,6 @@ import { createApi } from '@reduxjs/toolkit/query'
2
2
import { delay } from 'msw'
3
3
import { setupApiStore } from './helpers'
4
4
import type { SubscriptionSelectors } from '../core/buildMiddleware/types'
5
- import { createListenerMiddleware } from '@reduxjs/toolkit'
6
5
7
6
const mockBaseQuery = vi
8
7
. fn ( )
@@ -126,26 +125,18 @@ describe('polling tests', () => {
126
125
127
126
it ( 'respects skipPollOnFocusLost' , async ( ) => {
128
127
mockBaseQuery . mockClear ( )
129
- const listenerMiddleware = createListenerMiddleware ( )
130
- const storeListenerRef = setupApiStore ( api , undefined , {
131
- middleware : {
132
- concat : [ listenerMiddleware . middleware ] ,
133
- } ,
134
- withoutTestLifecycles : true ,
135
- } )
136
-
137
- storeListenerRef . store . dispatch (
128
+ storeRef . store . dispatch (
138
129
getPosts . initiate ( 2 , {
139
130
subscriptionOptions : { pollingInterval : 10 , skipPollOnFocusLost : true } ,
140
131
subscribe : true ,
141
132
} )
142
133
)
143
- storeListenerRef . store . dispatch ( api . internalActions ?. onFocusLost ( ) )
134
+ storeRef . store . dispatch ( api . internalActions ?. onFocusLost ( ) )
144
135
145
136
await delay ( 50 )
146
137
const callsWithSkip = mockBaseQuery . mock . calls . length
147
138
148
- storeListenerRef . store . dispatch (
139
+ storeRef . store . dispatch (
149
140
getPosts . initiate ( 2 , {
150
141
subscriptionOptions : {
151
142
pollingInterval : 10 ,
@@ -155,27 +146,19 @@ describe('polling tests', () => {
155
146
} )
156
147
)
157
148
158
- storeListenerRef . store . dispatch ( api . internalActions ?. onFocus ( ) )
149
+ storeRef . store . dispatch ( api . internalActions ?. onFocus ( ) )
159
150
160
151
await delay ( 50 )
161
152
const callsWithoutSkip = mockBaseQuery . mock . calls . length
162
153
163
154
expect ( callsWithSkip ) . toBe ( 1 )
164
155
expect ( callsWithoutSkip ) . toBeGreaterThan ( 2 )
165
156
166
- storeListenerRef . store . dispatch ( api . util . resetApiState ( ) )
157
+ storeRef . store . dispatch ( api . util . resetApiState ( ) )
167
158
} )
168
159
169
160
it ( 'respects skipPollOnFocusLost of the most recent mounted subscription' , async ( ) => {
170
- const listenerMiddleware = createListenerMiddleware ( )
171
- const storeListenerRef = setupApiStore ( api , undefined , {
172
- middleware : {
173
- concat : [ listenerMiddleware . middleware ] ,
174
- } ,
175
- withoutTestLifecycles : true ,
176
- } )
177
-
178
- storeListenerRef . store . dispatch (
161
+ storeRef . store . dispatch (
179
162
getPosts . initiate ( 3 , {
180
163
subscriptionOptions : {
181
164
pollingInterval : 10 ,
@@ -188,14 +171,14 @@ describe('polling tests', () => {
188
171
await delay ( 50 )
189
172
const callsWithSkip = mockBaseQuery . mock . calls . length
190
173
191
- storeListenerRef . store . dispatch (
174
+ storeRef . store . dispatch (
192
175
getPosts . initiate ( 3 , {
193
176
subscriptionOptions : { pollingInterval : 15 , skipPollOnFocusLost : true } ,
194
177
subscribe : true ,
195
178
} )
196
179
)
197
180
198
- storeListenerRef . store . dispatch ( api . internalActions ?. onFocusLost ( ) )
181
+ storeRef . store . dispatch ( api . internalActions ?. onFocusLost ( ) )
199
182
200
183
await delay ( 50 )
201
184
const callsWithoutSkip = mockBaseQuery . mock . calls . length
0 commit comments