diff --git a/src/request.js b/src/request.js index 0fae703..c897489 100644 --- a/src/request.js +++ b/src/request.js @@ -82,9 +82,8 @@ export default class Request extends Body { signal = init.signal; } - // eslint-disable-next-line no-eq-null, eqeqeq if (signal != null && !isAbortSignal(signal)) { - throw new TypeError('Expected signal to be an instanceof AbortSignal'); + throw new TypeError('Expected signal to be an instanceof AbortSignal or EventTarget'); } this[INTERNALS] = { diff --git a/src/utils/is.js b/src/utils/is.js index e48165d..fa8d159 100644 --- a/src/utils/is.js +++ b/src/utils/is.js @@ -74,8 +74,10 @@ export function isFormData(object) { */ export const isAbortSignal = object => { return ( - typeof object === 'object' && - object[NAME] === 'AbortSignal' + typeof object === 'object' && ( + object[NAME] === 'AbortSignal' || + object[NAME] === 'EventTarget' + ) ); }; diff --git a/test/main.js b/test/main.js index 59a719d..4e7bb67 100644 --- a/test/main.js +++ b/test/main.js @@ -1021,7 +1021,7 @@ describe('node-fetch', () => { return result; }); - it('should throw a TypeError if a signal is not of type AbortSignal', () => { + it('should throw a TypeError if a signal is not of type AbortSignal or EventTarget', () => { return Promise.all([ expect(fetch(`${base}inspect`, {signal: {}})) .to.be.eventually.rejected