From 88fb12f065b0de3242791248e1b16f3978d8dc71 Mon Sep 17 00:00:00 2001 From: Marais Rossouw Date: Thu, 24 Oct 2024 17:46:37 +1000 Subject: [PATCH] chore: we really should be using `promise_rejects_*` instead --- .../tentative/observable-first.any.js | 39 +++---------------- .../tentative/observable-last.any.js | 39 +++---------------- 2 files changed, 12 insertions(+), 66 deletions(-) diff --git a/dom/observable/tentative/observable-first.any.js b/dom/observable/tentative/observable-first.any.js index 826f11a8d2b796..e6551ed3783b5c 100644 --- a/dom/observable/tentative/observable-first.any.js +++ b/dom/observable/tentative/observable-first.any.js @@ -19,41 +19,25 @@ promise_test(async () => { "Promise resolves with the first value from the source Observable"); }, "first(): Promise resolves with the first value from the source Observable"); -promise_test(async () => { +promise_test(async (t) => { const error = new Error("error from source"); const source = new Observable(subscriber => { subscriber.error(error); }); - let rejection; - try { - await source.first(); - } catch (e) { - rejection = e; - } - - assert_equals(rejection, error, "Promise rejects with source Observable error"); + return promise_rejects_exactly(t, error, source.first(), "Promise rejects with source Observable error"); }, "first(): Promise rejects with the error emitted from the source Observable"); -promise_test(async () => { +promise_test(async (t) => { const source = new Observable(subscriber => { subscriber.complete(); }); - let rejection; - try { - await source.first(); - } catch (e) { - rejection = e; - } - - assert_true(rejection instanceof RangeError, - "Upon complete(), first() Promise rejects with RangeError"); - assert_true(typeof rejection.message === "string", "Rejection message must be a string"); + return promise_rejects_js(t, RangeError, source.first(), "Upon complete(), first() Promise rejects with RangeError"); }, "first(): Promise rejects with RangeError when source Observable " + "completes without emitting any values"); -promise_test(async () => { +promise_test(async (t) => { const source = new Observable(subscriber => {}); const controller = new AbortController(); @@ -61,18 +45,7 @@ promise_test(async () => { controller.abort(); - let rejection; - try { - await promise; - } catch (e) { - rejection = e; - } - - assert_true(rejection instanceof DOMException, - "Promise rejects with a DOMException for abortion"); - assert_equals(rejection.name, "AbortError", - "Rejected with 'AbortError' DOMException"); - assert_true(typeof rejection.message === "string", "Rejection message must be a string"); + return promise_rejects_dom(t, "AbortError", promise, "Promise rejects with a DOMException for abortion"); }, "first(): Aborting a signal rejects the Promise with an AbortError DOMException"); promise_test(async () => { diff --git a/dom/observable/tentative/observable-last.any.js b/dom/observable/tentative/observable-last.any.js index 994cc8e8f6782d..0acdafed92ec6a 100644 --- a/dom/observable/tentative/observable-last.any.js +++ b/dom/observable/tentative/observable-last.any.js @@ -12,41 +12,25 @@ promise_test(async () => { assert_equals(value, 2); }, "last(): Promise resolves to last value"); -promise_test(async () => { +promise_test(async (t) => { const error = new Error("error from source"); const source = new Observable(subscriber => { subscriber.error(error); }); - let rejection = null; - try { - await source.last(); - } catch (e) { - rejection = e; - } - - assert_equals(rejection, error); + return promise_rejects_exactly(t, error, source.last()); }, "last(): Promise rejects with emitted error"); -promise_test(async () => { +promise_test(async (t) => { const source = new Observable(subscriber => { subscriber.complete(); }); - let rejection = null; - try { - await source.last(); - } catch (e) { - rejection = e; - } - - assert_true(rejection instanceof RangeError, - "Promise rejects with RangeError"); - assert_true(typeof rejection.message === "string", "Rejection message must be a string"); + return promise_rejects_js(t, RangeError, source.last()); }, "last(): Promise rejects with RangeError when source Observable " + "completes without emitting any values"); -promise_test(async () => { +promise_test(async (t) => { const source = new Observable(subscriber => {}); const controller = new AbortController(); @@ -54,18 +38,7 @@ promise_test(async () => { controller.abort(); - let rejection = null; - try { - await promise; - } catch (e) { - rejection = e; - } - - assert_true(rejection instanceof DOMException, - "Promise rejects with a DOMException for abortion"); - assert_equals(rejection.name, "AbortError", - "Rejected with 'AbortError' DOMException"); - assert_equals(rejection.message, "signal is aborted without reason"); + return promise_rejects_dom(t, "AbortError", promise, "Promise rejects with a DOMException for abortion"); }, "last(): Aborting a signal rejects the Promise with an AbortError DOMException"); promise_test(async () => {