axios-axios/tests/unit/composeSignals.test.js
Jay fa337332b9
Update unit testing flows as part of migration to vitest (#7484)
* chore: small fixes to tests

* feat: transitional move to vitests

* feat: moving unit tests in progress

* feat: moving more unit tests over

* feat: more tests moved

* feat: updated more sections of the http test

* chore: wip http tests

* chore: wip http tests

* chore: more http tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: tests

* chore: remove un-needed docs

* chore: update package lock

* chore: update lock
2026-03-06 20:42:14 +02:00

41 lines
1.1 KiB
JavaScript

import { describe, it } from 'vitest';
import assert from 'assert';
import composeSignals from '../../lib/helpers/composeSignals.js';
describe('helpers::composeSignals', () => {
const runIfAbortController = typeof AbortController === 'function' ? it : it.skip;
runIfAbortController('should abort when any of the signals abort', () => {
let called;
const controllerA = new AbortController();
const controllerB = new AbortController();
const signal = composeSignals([controllerA.signal, controllerB.signal]);
signal.addEventListener('abort', () => {
called = true;
});
controllerA.abort(new Error('test'));
assert.ok(called);
});
runIfAbortController('should abort on timeout', async () => {
const signal = composeSignals([], 100);
await new Promise((resolve) => {
signal.addEventListener('abort', resolve);
});
assert.match(String(signal.reason), /timeout of 100ms exceeded/);
});
it('should return undefined if signals and timeout are not provided', () => {
const signal = composeSignals([]);
assert.strictEqual(signal, undefined);
});
});