Skip to content

Commit 534d0ee

Browse files
committed
Add a test
1 parent 8cf042b commit 534d0ee

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

packages/toolkit/src/query/tests/fetchBaseQuery.test.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,27 @@ describe('fetchBaseQuery', () => {
292292
expect(request.headers['content-type']).toBe('text/html')
293293
expect(request.body).toEqual(data.join(','))
294294
})
295+
296+
it('supports a custom jsonContentType', async () => {
297+
const baseQuery = fetchBaseQuery({
298+
baseUrl,
299+
fetchFn: fetchFn as any,
300+
jsonContentType: 'application/vnd.api+json',
301+
})
302+
303+
let request: any
304+
;({ data: request } = await baseQuery(
305+
{
306+
url: '/echo',
307+
body: {},
308+
method: 'POST',
309+
},
310+
commonBaseQueryApi,
311+
{}
312+
))
313+
314+
expect(request.headers['content-type']).toBe('application/vnd.api+json')
315+
})
295316
})
296317

297318
describe('arg.params', () => {
@@ -408,9 +429,11 @@ describe('fetchBaseQuery', () => {
408429
baseUrl,
409430
fetchFn: fetchFn as any,
410431
isJsonContentType: (headers) =>
411-
['application/vnd.api+json', 'application/json', 'application/vnd.hal+json'].includes(
412-
headers.get('content-type') ?? ''
413-
),
432+
[
433+
'application/vnd.api+json',
434+
'application/json',
435+
'application/vnd.hal+json',
436+
].includes(headers.get('content-type') ?? ''),
414437
})
415438

416439
let request: any

0 commit comments

Comments
 (0)