Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Mar 9, 2024
1 parent c6e6d82 commit 0a7682c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/options.signal.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
});
});
});

0 comments on commit 0a7682c

Please sign in to comment.