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'
119import {
220 TaskAbortError ,
321 addListener ,
@@ -10,28 +28,6 @@ import {
1028 removeListener ,
1129} from '@reduxjs/toolkit'
1230import 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'
3531
3632const middlewareApi = {
3733 getState : expect . any ( Function ) ,
@@ -51,8 +47,6 @@ const middlewareApi = {
5147 throwIfCancelled : expect . any ( Function ) ,
5248}
5349
54- const noop = ( ) => { }
55-
5650// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
5751export interface Deferred < T > extends Promise < T > {
5852 resolve ( value ?: T | PromiseLike < T > ) : void
@@ -176,7 +170,9 @@ describe('createListenerMiddleware', () => {
176170
177171 describe ( 'Subscription and unsubscription' , ( ) => {
178172 test ( 'directly subscribing' , ( ) => {
179- const effect = vi . fn ( ( _ : TestAction1 ) => { } )
173+ const effect = vi . fn ( ( _ : TestAction1 ) => {
174+ /** No-Op */
175+ } )
180176
181177 startListening ( {
182178 actionCreator : testAction1 ,
@@ -194,7 +190,9 @@ describe('createListenerMiddleware', () => {
194190 } )
195191
196192 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+ } )
198196
199197 startListening ( {
200198 actionCreator : testAction1 ,
@@ -206,7 +204,9 @@ describe('createListenerMiddleware', () => {
206204 } )
207205
208206 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+ } )
210210
211211 startListening ( {
212212 actionCreator : testAction1 ,
@@ -232,7 +232,9 @@ describe('createListenerMiddleware', () => {
232232 } )
233233
234234 test ( 'can subscribe with a string action type' , ( ) => {
235- const effect = vi . fn ( ( _ : UnknownAction ) => { } )
235+ const effect = vi . fn ( ( _ : UnknownAction ) => {
236+ /** No-Op */
237+ } )
236238
237239 store . dispatch (
238240 addListener ( {
@@ -251,7 +253,9 @@ describe('createListenerMiddleware', () => {
251253 } )
252254
253255 test ( 'can subscribe with a matcher function' , ( ) => {
254- const effect = vi . fn ( ( _ : UnknownAction ) => { } )
256+ const effect = vi . fn ( ( _ : UnknownAction ) => {
257+ /** No-Op */
258+ } )
255259
256260 const isAction1Or2 = isAnyOf ( testAction1 , testAction2 )
257261
@@ -318,7 +322,9 @@ describe('createListenerMiddleware', () => {
318322 } )
319323
320324 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+ } )
322328
323329 startListening ( {
324330 actionCreator : testAction1 ,
@@ -340,7 +346,9 @@ describe('createListenerMiddleware', () => {
340346 } )
341347
342348 test ( 'unsubscribing via callback' , ( ) => {
343- const effect = vi . fn ( ( _ : TestAction1 ) => { } )
349+ const effect = vi . fn ( ( _ : TestAction1 ) => {
350+ /** No-Op */
351+ } )
344352
345353 const unsubscribe = startListening ( {
346354 actionCreator : testAction1 ,
@@ -356,7 +364,9 @@ describe('createListenerMiddleware', () => {
356364 } )
357365
358366 test ( 'directly unsubscribing' , ( ) => {
359- const effect = vi . fn ( ( _ : TestAction1 ) => { } )
367+ const effect = vi . fn ( ( _ : TestAction1 ) => {
368+ /** No-Op */
369+ } )
360370
361371 startListening ( {
362372 actionCreator : testAction1 ,
@@ -377,7 +387,9 @@ describe('createListenerMiddleware', () => {
377387 } )
378388
379389 test ( 'subscribing via action' , ( ) => {
380- const effect = vi . fn ( ( _ : TestAction1 ) => { } )
390+ const effect = vi . fn ( ( _ : TestAction1 ) => {
391+ /** No-Op */
392+ } )
381393
382394 store . dispatch (
383395 addListener ( {
@@ -397,7 +409,9 @@ describe('createListenerMiddleware', () => {
397409 } )
398410
399411 test ( 'unsubscribing via callback from dispatch' , ( ) => {
400- const effect = vi . fn ( ( _ : TestAction1 ) => { } )
412+ const effect = vi . fn ( ( _ : TestAction1 ) => {
413+ /** No-Op */
414+ } )
401415
402416 const unsubscribe = store . dispatch (
403417 addListener ( {
@@ -416,7 +430,9 @@ describe('createListenerMiddleware', () => {
416430 } )
417431
418432 test ( 'unsubscribing via action' , ( ) => {
419- const effect = vi . fn ( ( _ : TestAction1 ) => { } )
433+ const effect = vi . fn ( ( _ : TestAction1 ) => {
434+ /** No-Op */
435+ } )
420436
421437 startListening ( {
422438 actionCreator : testAction1 ,
@@ -636,7 +652,7 @@ describe('createListenerMiddleware', () => {
636652 let listenerCancelled = false
637653 let listenerStarted = false
638654 let listenerCompleted = false
639- let cancelListener : ( ) => void = ( ) => { }
655+ let cancelListener : ( ) => void = noop
640656 let error : TaskAbortError | undefined = undefined
641657
642658 startListening ( {
@@ -928,7 +944,9 @@ describe('createListenerMiddleware', () => {
928944 test ( 'by default, actions are forwarded to the store' , ( ) => {
929945 reducer . mockClear ( )
930946
931- const effect = vi . fn ( ( _ : TestAction1 ) => { } )
947+ const effect = vi . fn ( ( _ : TestAction1 ) => {
948+ /** No-Op */
949+ } )
932950
933951 startListening ( {
934952 actionCreator : testAction1 ,
@@ -993,7 +1011,7 @@ describe('createListenerMiddleware', () => {
9931011 } ,
9941012 } )
9951013
996- const effect = vi . fn ( ( ) => { } )
1014+ const effect = vi . fn ( noop )
9971015 startListening ( { matcher, effect } )
9981016
9991017 store . dispatch ( testAction1 ( 'a' ) )
@@ -1002,8 +1020,8 @@ describe('createListenerMiddleware', () => {
10021020
10031021 test ( 'Continues running other listeners if a predicate raises an error' , ( ) => {
10041022 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 )
10071025
10081026 startListening ( {
10091027 // @ts -expect-error
0 commit comments