Skip to content

Commit

Permalink
chore: we really should be using promise_rejects_* instead (#48786)
Browse files Browse the repository at this point in the history
  • Loading branch information
maraisr authored Oct 24, 2024
1 parent 63e7ab0 commit 2a6f629
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 66 deletions.
39 changes: 6 additions & 33 deletions dom/observable/tentative/observable-first.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,33 @@ 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();
const promise = source.first({ signal: controller.signal });

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 () => {
Expand Down
39 changes: 6 additions & 33 deletions dom/observable/tentative/observable-last.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,60 +12,33 @@ 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();
const promise = source.last({ signal: controller.signal });

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 () => {
Expand Down

0 comments on commit 2a6f629

Please sign in to comment.