Skip to content

Commit c54dd95

Browse files
committed
Add isObject and hasBodyAndHeaders utility functions
1 parent ebc74ec commit c54dd95

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import type {
77
} from '@reduxjs/toolkit'
88
import { configureStore } from '@reduxjs/toolkit'
99
import { setupListeners } from '@reduxjs/toolkit/query'
10+
import { act, cleanup } from '@testing-library/react'
1011
import { useCallback, useEffect, useRef } from 'react'
11-
1212
import { Provider } from 'react-redux'
13-
14-
import { act, cleanup } from '@testing-library/react'
13+
import type { AnyObject } from '../../tsHelpers'
1514

1615
export const ANY = 0 as any
1716

@@ -215,3 +214,24 @@ export function setupApiStore<
215214

216215
return refObj
217216
}
217+
218+
export const isObject = (value: unknown): value is AnyObject => {
219+
return typeof value === 'object' && value != null
220+
}
221+
222+
export const hasBodyAndHeaders = (
223+
request: unknown,
224+
): request is {
225+
body: any
226+
headers: {
227+
'content-type': string
228+
}
229+
} => {
230+
return (
231+
isObject(request) &&
232+
'headers' in request &&
233+
isObject(request.headers) &&
234+
'content-type' in request.headers &&
235+
'body' in request
236+
)
237+
}

0 commit comments

Comments
 (0)