Skip to content

Commit

Permalink
chore: we really should be using promise_rejects_* instead
Browse files Browse the repository at this point in the history
  • Loading branch information
maraisr committed Oct 23, 2024
1 parent 69ce0d3 commit 24c776b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 62 deletions.
41 changes: 10 additions & 31 deletions dom/observable/tentative/observable-first.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,39 @@ 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;
}
await source.first();

assert_equals(rejection, error, "Promise rejects with source Observable error");
return promise_rejects_js(t, error, "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;
}
await source.first();

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_dom(t, "RangeError", "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");
await promise;

return promise_rejects_dom(t, "AbortError", "Promise rejects with a DOMException for abortion");
}, "first(): Aborting a signal rejects the Promise with an AbortError DOMException");

promise_test(async () => {
Expand Down
41 changes: 10 additions & 31 deletions dom/observable/tentative/observable-last.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,60 +12,39 @@ 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;
}
await source.last();

assert_equals(rejection, error);
return promise_rejects_js(t, error);
}, "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;
}
await source.last();

assert_true(rejection instanceof RangeError,
"Promise rejects with RangeError");
assert_true(typeof rejection.message === "string", "Rejection message must be a string");
return promise_rejects_dom(t, "RangeError")
}, "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");
await promise;

return promise_rejects_dom(t, "AbortError", "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 24c776b

Please sign in to comment.