Skip to content

Commit 8597a71

Browse files
committed
Remove declare global from helpers.tsx
- Now we can have an ambient declaration file to handle types for custom matchers.
1 parent 01bcfcc commit 8597a71

File tree

1 file changed

+9
-76
lines changed

1 file changed

+9
-76
lines changed

packages/toolkit/src/tests/utils/helpers.tsx

Lines changed: 9 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
import React, { useCallback } from 'react'
21
import type {
3-
UnknownAction,
42
EnhancedStore,
53
Middleware,
6-
Store,
74
Reducer,
5+
Store,
6+
UnknownAction,
87
} from '@reduxjs/toolkit'
98
import { configureStore } from '@reduxjs/toolkit'
109
import { setupListeners } from '@reduxjs/toolkit/query'
10+
import { useCallback, useEffect, useRef } from 'react'
1111

1212
import { Provider } from 'react-redux'
1313

14+
import { act, cleanup } from '@testing-library/react'
1415
import {
15-
mockConsole,
1616
createConsole,
1717
getLog,
18+
mockConsole,
1819
} from 'console-testing-library/pure'
19-
import { cleanup, act } from '@testing-library/react'
2020

2121
export const ANY = 0 as any
2222

2323
export const DEFAULT_DELAY_MS = 150
2424

2525
export const getSerializedHeaders = (headers: Headers = new Headers()) => {
26-
let result: Record<string, string> = {}
26+
const result: Record<string, string> = {}
2727
headers.forEach((val, key) => {
2828
result[key] = val
2929
})
@@ -83,13 +83,13 @@ export const fakeTimerWaitFor = async (cb: () => void, time = 2000) => {
8383
}
8484

8585
export const useRenderCounter = () => {
86-
const countRef = React.useRef(0)
86+
const countRef = useRef(0)
8787

88-
React.useEffect(() => {
88+
useEffect(() => {
8989
countRef.current += 1
9090
})
9191

92-
React.useEffect(() => {
92+
useEffect(() => {
9393
return () => {
9494
countRef.current = 0
9595
}
@@ -98,14 +98,6 @@ export const useRenderCounter = () => {
9898
return useCallback(() => countRef.current, [])
9999
}
100100

101-
declare global {
102-
namespace jest {
103-
interface Matchers<R> {
104-
toMatchSequence(...matchers: Array<(arg: any) => boolean>): R
105-
}
106-
}
107-
}
108-
109101
expect.extend({
110102
toMatchSequence(
111103
_actions: UnknownAction[],
@@ -276,62 +268,3 @@ export function setupApiStore<
276268

277269
return refObj
278270
}
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

Comments
 (0)