mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-24 19:39:11 +00:00
45 lines
927 B
TypeScript
45 lines
927 B
TypeScript
import { formData, formDataRequest, getQuery } from './request';
|
|
|
|
describe('getQuery', () => {
|
|
it('splits query string into object', () => {
|
|
const query = getQuery(new Request('http://local.test/?a=1&b=2'));
|
|
|
|
expect(query).toEqual({
|
|
a: '1',
|
|
b: '2',
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('formData & formDataRequest', () => {
|
|
it('formats object into form data', () => {
|
|
const body = formData({
|
|
a: 1,
|
|
b: 2,
|
|
});
|
|
|
|
expect(body).toEqual('a=1&b=2');
|
|
});
|
|
|
|
it('formats object into form data with custom headers', () => {
|
|
const body = formDataRequest(
|
|
{
|
|
a: 1,
|
|
b: 2,
|
|
},
|
|
{
|
|
headers: {
|
|
'content-type': 'application/x-www-form-urlencoded',
|
|
},
|
|
}
|
|
);
|
|
|
|
expect(body).toEqual({
|
|
method: 'POST',
|
|
headers: {
|
|
'content-type': 'application/x-www-form-urlencoded',
|
|
},
|
|
body: 'a=1&b=2',
|
|
});
|
|
});
|
|
});
|