2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00
Files
axios/tests/smoke/deno/tests/error.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

52 lines
1.3 KiB
TypeScript

import { assertEquals } from '@std/assert';
import axios from 'axios';
const env = (fetch: any) => ({
fetch,
Request,
Response,
});
Deno.test('errors: rejects with AxiosError for 500', async () => {
const fetch = async () =>
new Response(JSON.stringify({ error: 'boom' }), {
status: 500,
statusText: 'Internal Server Error',
headers: { 'Content-Type': 'application/json' },
});
const err = await axios
.get('https://example.com/fail', {
adapter: 'fetch',
env: env(fetch),
})
.catch((e: any) => e);
assertEquals(axios.isAxiosError(err), true);
assertEquals(err.response.status, 500);
assertEquals(err.response.data, { error: 'boom' });
});
Deno.test('errors: rejects with AxiosError for 404', async () => {
const fetch = async () =>
new Response(JSON.stringify({ error: 'missing' }), {
status: 404,
statusText: 'Not Found',
headers: { 'Content-Type': 'application/json' },
});
const err = await axios
.get('https://example.com/missing', {
adapter: 'fetch',
env: env(fetch),
})
.catch((e: any) => e);
assertEquals(axios.isAxiosError(err), true);
assertEquals(err.response.status, 404);
});
Deno.test('errors: isAxiosError returns false for plain Error', () => {
assertEquals(axios.isAxiosError(new Error('plain')), false);
});