1
- import React , { useCallback } from 'react'
2
1
import type {
3
- UnknownAction ,
4
2
EnhancedStore ,
5
3
Middleware ,
6
- Store ,
7
4
Reducer ,
5
+ Store ,
6
+ UnknownAction ,
8
7
} from '@reduxjs/toolkit'
9
8
import { configureStore } from '@reduxjs/toolkit'
10
9
import { setupListeners } from '@reduxjs/toolkit/query'
10
+ import { useCallback , useEffect , useRef } from 'react'
11
11
12
12
import { Provider } from 'react-redux'
13
13
14
+ import { act , cleanup } from '@testing-library/react'
14
15
import {
15
- mockConsole ,
16
16
createConsole ,
17
17
getLog ,
18
+ mockConsole ,
18
19
} from 'console-testing-library/pure'
19
- import { cleanup , act } from '@testing-library/react'
20
20
21
21
export const ANY = 0 as any
22
22
23
23
export const DEFAULT_DELAY_MS = 150
24
24
25
25
export const getSerializedHeaders = ( headers : Headers = new Headers ( ) ) => {
26
- let result : Record < string , string > = { }
26
+ const result : Record < string , string > = { }
27
27
headers . forEach ( ( val , key ) => {
28
28
result [ key ] = val
29
29
} )
@@ -83,13 +83,13 @@ export const fakeTimerWaitFor = async (cb: () => void, time = 2000) => {
83
83
}
84
84
85
85
export const useRenderCounter = ( ) => {
86
- const countRef = React . useRef ( 0 )
86
+ const countRef = useRef ( 0 )
87
87
88
- React . useEffect ( ( ) => {
88
+ useEffect ( ( ) => {
89
89
countRef . current += 1
90
90
} )
91
91
92
- React . useEffect ( ( ) => {
92
+ useEffect ( ( ) => {
93
93
return ( ) => {
94
94
countRef . current = 0
95
95
}
@@ -98,14 +98,6 @@ export const useRenderCounter = () => {
98
98
return useCallback ( ( ) => countRef . current , [ ] )
99
99
}
100
100
101
- declare global {
102
- namespace jest {
103
- interface Matchers < R > {
104
- toMatchSequence ( ...matchers : Array < ( arg : any ) => boolean > ) : R
105
- }
106
- }
107
- }
108
-
109
101
expect . extend ( {
110
102
toMatchSequence (
111
103
_actions : UnknownAction [ ] ,
@@ -276,62 +268,3 @@ export function setupApiStore<
276
268
277
269
return refObj
278
270
}
279
-
280
- // type test helpers
281
-
282
- export declare type IsAny < T , True , False = never > = true | false extends (
283
- T extends never ? true : false
284
- )
285
- ? True
286
- : False
287
-
288
- export declare type IsUnknown < T , True , False = never > = unknown extends T
289
- ? IsAny < T , False , True >
290
- : False
291
-
292
- export function expectType < T > ( t : T ) : T {
293
- return t
294
- }
295
-
296
- type Equals < T , U > = IsAny <
297
- T ,
298
- never ,
299
- IsAny < U , never , [ T ] extends [ U ] ? ( [ U ] extends [ T ] ? any : never ) : never >
300
- >
301
- export function expectExactType < T > ( t : T ) {
302
- return < U extends Equals < T , U > > ( u : U ) => { }
303
- }
304
-
305
- type EnsureUnknown < T extends any > = IsUnknown < T , any , never >
306
- export function expectUnknown < T extends EnsureUnknown < T > > ( t : T ) {
307
- return t
308
- }
309
-
310
- type EnsureAny < T extends any > = IsAny < T , any , never >
311
- export function expectExactAny < T extends EnsureAny < T > > ( t : T ) {
312
- return t
313
- }
314
-
315
- type IsNotAny < T > = IsAny < T , never , any >
316
- export function expectNotAny < T extends IsNotAny < T > > ( t : T ) : T {
317
- return t
318
- }
319
-
320
- expectType < string > ( '5' as string )
321
- expectType < string > ( '5' as const )
322
- expectType < string > ( '5' as any )
323
- expectExactType ( '5' as const ) ( '5' as const )
324
- // @ts -expect-error
325
- expectExactType ( '5' as string ) ( '5' as const )
326
- // @ts -expect-error
327
- expectExactType ( '5' as any ) ( '5' as const )
328
- expectUnknown ( '5' as unknown )
329
- // @ts -expect-error
330
- expectUnknown ( '5' as const )
331
- // @ts -expect-error
332
- expectUnknown ( '5' as any )
333
- expectExactAny ( '5' as any )
334
- // @ts -expect-error
335
- expectExactAny ( '5' as const )
336
- // @ts -expect-error
337
- expectExactAny ( '5' as unknown )
0 commit comments