Spaces:
Running
Running
File size: 1,032 Bytes
d4b85c0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
/**
* @vitest-environment jsdom
*/
import { TextEncoder } from 'util'
import { pruneGetRequestBody } from './pruneGetRequestBody'
test('sets empty GET request body to undefined', () => {
expect(
pruneGetRequestBody({
method: 'GET',
}),
).toBeUndefined()
expect(
pruneGetRequestBody({
method: 'GET',
// There's no such thing as a GET request with a body.
body: new ArrayBuffer(5),
}),
).toBeUndefined()
})
test('sets HEAD request body to undefined', () => {
expect(
pruneGetRequestBody({
method: 'HEAD',
}),
).toBeUndefined()
expect(
pruneGetRequestBody({
method: 'HEAD',
body: new ArrayBuffer(5),
}),
).toBeUndefined()
})
test('ignores requests of the other methods than GET', () => {
const body = new TextEncoder().encode('hello world')
expect(
pruneGetRequestBody({
method: 'POST',
body,
}),
).toEqual(body)
expect(
pruneGetRequestBody({
method: 'PUT',
body,
}),
).toEqual(body)
})
|