diff --git a/test/options.signal.test.ts b/test/options.signal.test.ts index 711377bc..0ea2f0e4 100644 --- a/test/options.signal.test.ts +++ b/test/options.signal.test.ts @@ -1,4 +1,5 @@ import { strict as assert } from 'node:assert'; +import { EventEmitter } from 'node:events'; import { describe, it, beforeAll, afterAll } from 'vitest'; import urllib from '../src'; import { startServer } from './fixtures/server'; @@ -34,4 +35,22 @@ describe('options.signal.test.ts', () => { return true; }); }); + + it('should throw error when EventEmitter emit abort event', async () => { + await assert.rejects(async () => { + const ee = new EventEmitter(); + const p = urllib.request(`${_url}?timeout=2000`, { + signal: ee, + }); + await sleep(100); + ee.emit('abort'); + await p; + }, (err: any) => { + // console.error(err); + assert.equal(err.name, 'AbortError'); + assert.equal(err.message, 'Request aborted'); + assert.equal(err.code, 'UND_ERR_ABORTED'); + return true; + }); + }); });