mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
997 B
49 lines
997 B
Promise.all = undefined |
|
// /*/ // ⚡ |
|
export const tests = [] |
|
const t = (f) => tests.push(f) |
|
|
|
// it should work with an empty object |
|
t(async ({ eq }) => eq(await all({}), {})) |
|
|
|
// it should work with synchronous values |
|
t(async ({ eq }) => eq(await all({ a: 1, b: true }), { a: 1, b: true })) |
|
|
|
// it should work with pending promises |
|
t(async ({ eq }) => |
|
eq( |
|
await all({ |
|
a: Promise.resolve(1), |
|
b: Promise.resolve(true), |
|
}), |
|
{ a: 1, b: true }, |
|
), |
|
) |
|
|
|
// it should work with pending promises and synchronous values |
|
t(async ({ eq, ctx }) => |
|
eq( |
|
await all( |
|
Object.freeze({ |
|
a: Promise.resolve(ctx).then((v) => v + 1), |
|
b: ctx, |
|
}), |
|
), |
|
{ a: ctx + 1, b: ctx }, |
|
), |
|
) |
|
|
|
// it should fail if one of the promises reject |
|
t(async ({ eq }) => |
|
eq( |
|
await all({ |
|
a: Promise.resolve(1), |
|
b: Promise.reject(Error('oops')), |
|
}).catch((err) => err.message), |
|
'oops', |
|
), |
|
) |
|
|
|
Object.freeze(tests) |
|
|
|
export const setup = Math.random
|
|
|