Skip to content

Commit

Permalink
Tests for abortSignal.throwIfAborted()
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell authored Dec 8, 2021
1 parent 11ddb98 commit b03df35
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions dom/abort/event.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,23 @@ test(t => {
assert_equals(signal.reason, reason, "signal.reason");
}, "static aborting signal with reason should set signal.reason");

test(t => {
const reason = new Error('boom');
const signal = AbortSignal.abort(reason);
assert_true(signal.aborted);
assert_throws_exactly(reason, () => signal.throwIfAborted());
}, "throwIfAborted() should throw abort.reason if signal aborted");

test(t => {
const signal = AbortSignal.abort('hello');
assert_true(signal.aborted);
assert_throws_exactly('hello', () => signal.throwIfAborted());
}, "throwIfAborted() should throw primitive abort.reason if signal aborted");

test(t => {
const controller = new AbortController();
assert_false(controller.signal.aborted);
controller.signal.throwIfAborted();
}, "throwIfAborted() should not throw if signal not aborted");

done();

0 comments on commit b03df35

Please sign in to comment.