1
+ import {
2
+ listenerCancelled ,
3
+ listenerCompleted ,
4
+ } from '@internal/listenerMiddleware/exceptions'
5
+ import type {
6
+ AbortSignalWithReason ,
7
+ AddListenerOverloads ,
8
+ } from '@internal/listenerMiddleware/types'
9
+ import { noop } from '@internal/tests/utils/helpers'
10
+ import type {
11
+ Action ,
12
+ ListenerEffect ,
13
+ ListenerEffectAPI ,
14
+ PayloadAction ,
15
+ TypedRemoveListener ,
16
+ TypedStartListening ,
17
+ UnknownAction ,
18
+ } from '@reduxjs/toolkit'
1
19
import {
2
20
TaskAbortError ,
3
21
addListener ,
@@ -10,28 +28,6 @@ import {
10
28
removeListener ,
11
29
} from '@reduxjs/toolkit'
12
30
import type { Mock } from 'vitest'
13
- import { vi } from 'vitest'
14
-
15
- import type {
16
- Action ,
17
- ListenerEffect ,
18
- ListenerEffectAPI ,
19
- PayloadAction ,
20
- TypedAddListener ,
21
- TypedRemoveListener ,
22
- TypedStartListening ,
23
- UnknownAction ,
24
- } from '@reduxjs/toolkit'
25
-
26
- import {
27
- listenerCancelled ,
28
- listenerCompleted ,
29
- } from '@internal/listenerMiddleware/exceptions'
30
-
31
- import type {
32
- AbortSignalWithReason ,
33
- AddListenerOverloads ,
34
- } from '@internal/listenerMiddleware/types'
35
31
36
32
const middlewareApi = {
37
33
getState : expect . any ( Function ) ,
@@ -51,8 +47,6 @@ const middlewareApi = {
51
47
throwIfCancelled : expect . any ( Function ) ,
52
48
}
53
49
54
- const noop = ( ) => { }
55
-
56
50
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
57
51
export interface Deferred < T > extends Promise < T > {
58
52
resolve ( value ?: T | PromiseLike < T > ) : void
@@ -176,7 +170,9 @@ describe('createListenerMiddleware', () => {
176
170
177
171
describe ( 'Subscription and unsubscription' , ( ) => {
178
172
test ( 'directly subscribing' , ( ) => {
179
- const effect = vi . fn ( ( _ : TestAction1 ) => { } )
173
+ const effect = vi . fn ( ( _ : TestAction1 ) => {
174
+ /** No-Op */
175
+ } )
180
176
181
177
startListening ( {
182
178
actionCreator : testAction1 ,
@@ -194,7 +190,9 @@ describe('createListenerMiddleware', () => {
194
190
} )
195
191
196
192
test ( 'stopListening returns true if an entry has been unsubscribed, false otherwise' , ( ) => {
197
- const effect = vi . fn ( ( _ : TestAction1 ) => { } )
193
+ const effect = vi . fn ( ( _ : TestAction1 ) => {
194
+ /** No-Op */
195
+ } )
198
196
199
197
startListening ( {
200
198
actionCreator : testAction1 ,
@@ -206,7 +204,9 @@ describe('createListenerMiddleware', () => {
206
204
} )
207
205
208
206
test ( 'dispatch(removeListener({...})) returns true if an entry has been unsubscribed, false otherwise' , ( ) => {
209
- const effect = vi . fn ( ( _ : TestAction1 ) => { } )
207
+ const effect = vi . fn ( ( _ : TestAction1 ) => {
208
+ /** No-Op */
209
+ } )
210
210
211
211
startListening ( {
212
212
actionCreator : testAction1 ,
@@ -232,7 +232,9 @@ describe('createListenerMiddleware', () => {
232
232
} )
233
233
234
234
test ( 'can subscribe with a string action type' , ( ) => {
235
- const effect = vi . fn ( ( _ : UnknownAction ) => { } )
235
+ const effect = vi . fn ( ( _ : UnknownAction ) => {
236
+ /** No-Op */
237
+ } )
236
238
237
239
store . dispatch (
238
240
addListener ( {
@@ -251,7 +253,9 @@ describe('createListenerMiddleware', () => {
251
253
} )
252
254
253
255
test ( 'can subscribe with a matcher function' , ( ) => {
254
- const effect = vi . fn ( ( _ : UnknownAction ) => { } )
256
+ const effect = vi . fn ( ( _ : UnknownAction ) => {
257
+ /** No-Op */
258
+ } )
255
259
256
260
const isAction1Or2 = isAnyOf ( testAction1 , testAction2 )
257
261
@@ -318,7 +322,9 @@ describe('createListenerMiddleware', () => {
318
322
} )
319
323
320
324
test ( 'subscribing with the same listener will not make it trigger twice (like EventTarget.addEventListener())' , ( ) => {
321
- const effect = vi . fn ( ( _ : TestAction1 ) => { } )
325
+ const effect = vi . fn ( ( _ : TestAction1 ) => {
326
+ /** No-Op */
327
+ } )
322
328
323
329
startListening ( {
324
330
actionCreator : testAction1 ,
@@ -340,7 +346,9 @@ describe('createListenerMiddleware', () => {
340
346
} )
341
347
342
348
test ( 'unsubscribing via callback' , ( ) => {
343
- const effect = vi . fn ( ( _ : TestAction1 ) => { } )
349
+ const effect = vi . fn ( ( _ : TestAction1 ) => {
350
+ /** No-Op */
351
+ } )
344
352
345
353
const unsubscribe = startListening ( {
346
354
actionCreator : testAction1 ,
@@ -356,7 +364,9 @@ describe('createListenerMiddleware', () => {
356
364
} )
357
365
358
366
test ( 'directly unsubscribing' , ( ) => {
359
- const effect = vi . fn ( ( _ : TestAction1 ) => { } )
367
+ const effect = vi . fn ( ( _ : TestAction1 ) => {
368
+ /** No-Op */
369
+ } )
360
370
361
371
startListening ( {
362
372
actionCreator : testAction1 ,
@@ -377,7 +387,9 @@ describe('createListenerMiddleware', () => {
377
387
} )
378
388
379
389
test ( 'subscribing via action' , ( ) => {
380
- const effect = vi . fn ( ( _ : TestAction1 ) => { } )
390
+ const effect = vi . fn ( ( _ : TestAction1 ) => {
391
+ /** No-Op */
392
+ } )
381
393
382
394
store . dispatch (
383
395
addListener ( {
@@ -397,7 +409,9 @@ describe('createListenerMiddleware', () => {
397
409
} )
398
410
399
411
test ( 'unsubscribing via callback from dispatch' , ( ) => {
400
- const effect = vi . fn ( ( _ : TestAction1 ) => { } )
412
+ const effect = vi . fn ( ( _ : TestAction1 ) => {
413
+ /** No-Op */
414
+ } )
401
415
402
416
const unsubscribe = store . dispatch (
403
417
addListener ( {
@@ -416,7 +430,9 @@ describe('createListenerMiddleware', () => {
416
430
} )
417
431
418
432
test ( 'unsubscribing via action' , ( ) => {
419
- const effect = vi . fn ( ( _ : TestAction1 ) => { } )
433
+ const effect = vi . fn ( ( _ : TestAction1 ) => {
434
+ /** No-Op */
435
+ } )
420
436
421
437
startListening ( {
422
438
actionCreator : testAction1 ,
@@ -636,7 +652,7 @@ describe('createListenerMiddleware', () => {
636
652
let listenerCancelled = false
637
653
let listenerStarted = false
638
654
let listenerCompleted = false
639
- let cancelListener : ( ) => void = ( ) => { }
655
+ let cancelListener : ( ) => void = noop
640
656
let error : TaskAbortError | undefined = undefined
641
657
642
658
startListening ( {
@@ -928,7 +944,9 @@ describe('createListenerMiddleware', () => {
928
944
test ( 'by default, actions are forwarded to the store' , ( ) => {
929
945
reducer . mockClear ( )
930
946
931
- const effect = vi . fn ( ( _ : TestAction1 ) => { } )
947
+ const effect = vi . fn ( ( _ : TestAction1 ) => {
948
+ /** No-Op */
949
+ } )
932
950
933
951
startListening ( {
934
952
actionCreator : testAction1 ,
@@ -993,7 +1011,7 @@ describe('createListenerMiddleware', () => {
993
1011
} ,
994
1012
} )
995
1013
996
- const effect = vi . fn ( ( ) => { } )
1014
+ const effect = vi . fn ( noop )
997
1015
startListening ( { matcher, effect } )
998
1016
999
1017
store . dispatch ( testAction1 ( 'a' ) )
@@ -1002,8 +1020,8 @@ describe('createListenerMiddleware', () => {
1002
1020
1003
1021
test ( 'Continues running other listeners if a predicate raises an error' , ( ) => {
1004
1022
const matcher = ( action : any ) : action is any => true
1005
- const firstListener = vi . fn ( ( ) => { } )
1006
- const secondListener = vi . fn ( ( ) => { } )
1023
+ const firstListener = vi . fn ( noop )
1024
+ const secondListener = vi . fn ( noop )
1007
1025
1008
1026
startListening ( {
1009
1027
// @ts -expect-error
0 commit comments