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.

54 lines
1006 B

5 years ago
Promise.all = undefined
// /*/ // ⚡
export const tests = []
const t = (f) => tests.push(f)
t(async ({ eq }) =>
// it should work with an empty object
eq(await all({}), {})
)
5 years ago
t(async ({ eq }) =>
// it should work with synchronous values
eq(await all({ a: 1, b: true }), { a: 1, b: true })
)
5 years ago
t(async ({ eq }) =>
// it should work with pending promises
5 years ago
eq(
await all({
a: Promise.resolve(1),
b: Promise.resolve(true),
}),
{ a: 1, b: true }
)
5 years ago
)
t(async ({ eq, ctx }) =>
// it should work with pending promises and synchronous values
5 years ago
eq(
await all(
Object.freeze({
a: Promise.resolve(ctx).then((v) => v + 1),
b: ctx,
})
5 years ago
),
{ a: ctx + 1, b: ctx }
)
5 years ago
)
t(async ({ eq }) =>
// it should fail if one of the promises reject
5 years ago
eq(
await all({
a: Promise.resolve(1),
b: Promise.reject(Error('oops')),
}).catch((err) => err.message),
'oops'
)
5 years ago
)
Object.freeze(tests)
export const setup = Math.random