mirror of
https://github.com/hanzoai/msw.git
synced 2026-09-24 17:00:34 +00:00
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { test, expect } from '../playwright.extend'
|
|
|
|
const EXAMPLE_PATH = new URL('./headers-multiple.mocks.ts', import.meta.url)
|
|
|
|
test('receives all headers from the request header with multiple values', async ({
|
|
loadExample,
|
|
fetch,
|
|
}) => {
|
|
await loadExample(EXAMPLE_PATH)
|
|
|
|
const headers = new Headers({ 'x-header': 'application/json' })
|
|
headers.append('x-header', 'application/hal+json')
|
|
|
|
const res = await fetch('https://test.mswjs.io', {
|
|
method: 'POST',
|
|
headers: Object.fromEntries(headers.entries()),
|
|
})
|
|
const status = res.status()
|
|
const body = await res.json()
|
|
|
|
expect(status).toBe(200)
|
|
expect(body).toEqual({
|
|
/**
|
|
* @fixme Multiple headers value becomes incompatible
|
|
* with the latest testing setup changes.
|
|
*/
|
|
'x-header': 'application/json, application/hal+json',
|
|
})
|
|
})
|
|
|
|
test('supports setting a header with multiple values on the mocked response', async ({
|
|
loadExample,
|
|
fetch,
|
|
}) => {
|
|
await loadExample(EXAMPLE_PATH)
|
|
|
|
const res = await fetch('https://test.mswjs.io')
|
|
const status = res.status()
|
|
const headers = await res.allHeaders()
|
|
const body = await res.json()
|
|
|
|
expect(status).toBe(200)
|
|
expect(headers).toHaveProperty('accept', 'application/json, image/png')
|
|
expect(body).toEqual({
|
|
mocked: true,
|
|
})
|
|
})
|