Skip to content

Commit

Permalink
chore: add resolvable headers test
Browse files Browse the repository at this point in the history
  • Loading branch information
maxholman committed Oct 29, 2022
1 parent 1b6052d commit 160f179
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions __tests__/fetcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ const server = createServer((req, res) => {
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8' });
res.end(JSON.stringify([1, 2, 3]));
break;
case '/my-headers':
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8' });
res.end(
JSON.stringify({
...req.headers,
host: 'redacted', // redacted as it changes every test run
}),
);
break;
case '/json-error':
res.writeHead(400, { 'content-type': 'application/json; charset=utf-8' });
res.end(
Expand Down Expand Up @@ -61,6 +70,44 @@ describe('Fetcher', () => {
);
});

test('Headers', async () => {
const response = await isomorphicFetcher({
method: 'get',
url: new URL('/my-headers', base),
headers: {
'x-async': () => Promise.resolve('Bearer 1234567890'),
'x-func': () => 'hello',
'x-primitive': 'hello',
},
});

expect(response).toMatchInlineSnapshot(
{
url: expect.any(URL),
},
`
{
"body": {
"accept": "*/*",
"accept-encoding": "gzip, deflate",
"accept-language": "*",
"connection": "keep-alive",
"host": "redacted",
"sec-fetch-mode": "cors",
"user-agent": "undici",
"x-async": "Bearer 1234567890",
"x-func": "hello",
"x-primitive": "hello",
},
"ok": true,
"status": 200,
"statusText": "OK",
"url": Any<URL>,
}
`,
);
});

test('JSON Error', async () => {
const response = await isomorphicFetcher({
method: 'get',
Expand Down

0 comments on commit 160f179

Please sign in to comment.