-
Notifications
You must be signed in to change notification settings - Fork 18
/
FirstAsync.ts
34 lines (27 loc) · 1.37 KB
/
FirstAsync.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { InvalidOperationException } from "linq-to-typescript"
import { asAsync, expectAsync, itAsync, itEnumerableAsync, itParallel } from "../TestHelpers"
describe("firstAsync", () => {
itEnumerableAsync("FirstPredicate", async (asEnumerable) => {
expect(await asEnumerable([1, 2]).firstAsync(async (x) => x === 2))
.toBe(2)
})
itAsync("FirstPredicate", async () => {
expect(await asAsync([1, 2]).firstAsync(async (x) => x === 2)).toBe(2)
})
itParallel("FirstPredicate", async (asParallel) => {
expect(await asParallel([1, 2]).firstAsync(async (x) => x === 2)).toBe(2)
})
itEnumerableAsync("Empty array with predicate causes exception", async (asEnumerable) => {
const promise = asEnumerable([1, 2, 3]).firstAsync(async (x) => x === 4)
const expectExpr = await expectAsync(promise)
expectExpr.toThrowError(InvalidOperationException)
})
itAsync("Empty array with predicate causes exception", async () => {
const value = await expectAsync(asAsync([1, 2, 3]).firstAsync(async (x) => x === 4))
value.toThrowError(InvalidOperationException)
})
itParallel("Empty array with predicate causes exception", async (asParallel) => {
const value = await expectAsync(asParallel([1, 2, 3]).firstAsync(async (x) => x === 4))
value.toThrowError(InvalidOperationException)
})
})