2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00
Files
axios/tests/smoke/bun/tests/headers.smoke.test.ts
T
Jay 2f52f6b13b feat: add checks to support deno and bun (#10652)
* feat: added smoke tests for deno

* feat: added bun smoke tests

* chore: added workflows for deno and bun

* chore: swap workflow implementation

* chore: apply ai suggestion

* chore: test alt install of bun deps

* chore: deno install

* chore: map bun file install

* chore: try a different approach for bun

* chore: unpack and then install for bun

* chore: remove un-needed step

* chore: try with tgx again for bun

* chore: alternative zip approach

* ci: full ci added back
2026-04-05 14:37:16 +02:00

63 lines
1.5 KiB
TypeScript

import { describe, expect, test } from 'bun:test';
import axios from 'axios';
const createFetchCapture = () => {
const calls: Request[] = [];
const fetch = async (input: unknown, init?: RequestInit) => {
const request = input instanceof Request ? input : new Request(input as string, init);
calls.push(request);
return new Response(JSON.stringify({ ok: true }), {
status: 200,
headers: { 'Content-Type': 'application/json' },
});
};
return {
fetch,
getCalls: () => calls,
};
};
const env = (fetch: typeof globalThis.fetch) => ({
fetch,
Request,
Response,
});
describe('headers', () => {
test('custom X-Custom header is forwarded to mock fetch (case-insensitive)', async () => {
const { fetch, getCalls } = createFetchCapture();
await axios.get('https://example.com/custom-headers', {
adapter: 'fetch',
headers: {
'X-Custom': 'trace-123',
},
env: env(fetch),
});
const request = getCalls()[0];
expect(request.headers.get('x-custom')).toBe('trace-123');
});
test('content-type application/json is inferred for JSON POST body', async () => {
const { fetch, getCalls } = createFetchCapture();
await axios.post(
'https://example.com/post-json',
{ name: 'widget' },
{
adapter: 'fetch',
env: env(fetch),
}
);
const request = getCalls()[0];
const contentType = request.headers.get('content-type') || '';
expect(contentType.includes('application/json')).toBe(true);
});
});