Skip to content

Commit f3914fd

Browse files
committed
Add isObject and hasBodyAndHeaders utility functions
1 parent 099f406 commit f3914fd

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@ import type {
77
} from '@reduxjs/toolkit'
88
import { configureStore } from '@reduxjs/toolkit'
99
import { setupListeners } from '@reduxjs/toolkit/query'
10-
import { useCallback, useEffect, useRef } from 'react'
11-
12-
import { Provider } from 'react-redux'
13-
1410
import { act, cleanup } from '@testing-library/react'
1511
import {
1612
createConsole,
1713
getLog,
1814
mockConsole,
1915
} from 'console-testing-library/pure'
16+
import { useCallback, useEffect, useRef } from 'react'
17+
import { Provider } from 'react-redux'
18+
import type { AnyObject } from '../../tsHelpers'
2019

2120
export const ANY = 0 as any
2221

@@ -268,3 +267,24 @@ export function setupApiStore<
268267

269268
return refObj
270269
}
270+
271+
export const isObject = (value: unknown): value is AnyObject => {
272+
return typeof value === 'object' && value != null
273+
}
274+
275+
export const hasBodyAndHeaders = (
276+
request: unknown,
277+
): request is {
278+
body: any
279+
headers: {
280+
'content-type': string
281+
}
282+
} => {
283+
return (
284+
isObject(request) &&
285+
'headers' in request &&
286+
isObject(request.headers) &&
287+
'content-type' in request.headers &&
288+
'body' in request
289+
)
290+
}

0 commit comments

Comments
 (0)