diff options
author | James M Snell <jasnell@gmail.com> | 2021-11-24 07:28:30 -0800 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2021-12-10 07:51:41 -0800 |
commit | 3f72c72bbb89154bc15fbcef7ccbe3cf0dd017ba (patch) | |
tree | f00850045d79c068969f28771f6a7b9776788544 /test/parallel/test-abortcontroller.js | |
parent | 03c983745706c4b05ff5579dcd4870f89d799d4b (diff) | |
download | node-new-3f72c72bbb89154bc15fbcef7ccbe3cf0dd017ba.tar.gz |
lib: add abortSignal.throwIfAborted()
Refs: https://github.com/whatwg/dom/pull/1034
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/40951
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'test/parallel/test-abortcontroller.js')
-rw-r--r-- | test/parallel/test-abortcontroller.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/parallel/test-abortcontroller.js b/test/parallel/test-abortcontroller.js index 4b59ae6adf..aa7aa916e6 100644 --- a/test/parallel/test-abortcontroller.js +++ b/test/parallel/test-abortcontroller.js @@ -230,3 +230,24 @@ const { setTimeout: sleep } = require('timers/promises'); // keep the Node.js process open (the timer is unref'd) AbortSignal.timeout(1_200_000); } + +{ + // Test AbortSignal.reason default + const signal = AbortSignal.abort(); + ok(signal.reason instanceof DOMException); + strictEqual(signal.reason.code, 20); + + const ac = new AbortController(); + ac.abort(); + ok(ac.signal.reason instanceof DOMException); + strictEqual(ac.signal.reason.code, 20); +} + +{ + // Test abortSignal.throwIfAborted() + throws(() => AbortSignal.abort().throwIfAborted(), { code: 20 }); + + // Does not throw because it's not aborted. + const ac = new AbortController(); + ac.signal.throwIfAborted(); +} |