Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We really should be using promise_rejects_* instead #48786

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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