Skip to content

Commit

Permalink
test(lib): some additional error throwing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerAberbach committed Nov 27, 2024
1 parent 129022d commit 159baad
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions test/operations/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import withElapsed from 'test/helpers/with-elapsed.js'
import {
asAsync,
asConcur,
consumeAsync,
consumeConcur,
exclude,
excludeAsync,
Expand Down Expand Up @@ -165,6 +166,33 @@ test.prop([asyncIterableArb])(
},
)

test.prop([nonEmptyAsyncIterableArb])(
`filterAsync rejects for a sync throwing function and non-empty async iterable`,
async ({ iterable }) => {
const filteredIterable = filterAsync(() => {
throw new Error(`BOOM!`)
}, iterable)

await expect(consumeAsync(filteredIterable)).rejects.toStrictEqual(
new Error(`BOOM!`),
)
},
)

test.prop([nonEmptyAsyncIterableArb])(
`filterAsync rejects for an async throwing function and non-empty async iterable`,
async ({ iterable }) => {
const filteredIterable = filterAsync(
() => Promise.reject(new Error(`BOOM!`)),
iterable,
)

await expect(consumeAsync(filteredIterable)).rejects.toStrictEqual(
new Error(`BOOM!`),
)
},
)

test.skip(`filterConcur types are correct`, () => {
expectTypeOf(
pipe(
Expand Down Expand Up @@ -234,6 +262,33 @@ test.prop([asyncPredicateArb, uniqueConcurIterableArb])(
},
)

test.prop([nonEmptyConcurIterableArb])(
`filterConcur rejects for a sync throwing function and non-empty concur iterable`,
async ({ iterable }) => {
const filteredIterable = filterConcur(() => {
throw new Error(`BOOM!`)
}, iterable)

await expect(consumeConcur(filteredIterable)).rejects.toStrictEqual(
new Error(`BOOM!`),
)
},
)

test.prop([nonEmptyConcurIterableArb])(
`filterConcur rejects for an async throwing function and non-empty concur iterable`,
async ({ iterable }) => {
const filteredIterable = filterConcur(
() => Promise.reject(new Error(`BOOM!`)),
iterable,
)

await expect(consumeConcur(filteredIterable)).rejects.toStrictEqual(
new Error(`BOOM!`),
)
},
)

test.skip(`filterMap types are correct`, () => {
expectTypeOf(
pipe(
Expand Down Expand Up @@ -967,6 +1022,26 @@ test.prop([asyncPredicateArb, concurIterableArb])(
},
)

test.prop([nonEmptyConcurIterableArb])(
`findConcur rejects for a sync throwing function and non-empty concur iterable`,
async ({ iterable }) => {
await expect(
findConcur(() => {
throw new Error(`BOOM!`)
}, iterable),
).rejects.toStrictEqual(new Error(`BOOM!`))
},
)

test.prop([nonEmptyConcurIterableArb])(
`findConcur rejects for an async throwing function and non-empty concur iterable`,
async ({ iterable }) => {
await expect(
findConcur(() => Promise.reject(new Error(`BOOM!`)), iterable),
).rejects.toStrictEqual(new Error(`BOOM!`))
},
)

test.skip(`findLast types are correct`, () => {
expectTypeOf(
pipe(
Expand Down

0 comments on commit 159baad

Please sign in to comment.