-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathsingle-spec.ts
35 lines (28 loc) · 1.03 KB
/
single-spec.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
35
import '../iterablehelpers';
import { single } from 'ix/iterable/index.js';
test('Iterable#single no predicate empty returns undefined', () => {
const res = single<number>([]);
expect(res).toBeUndefined();
});
test('Iterable#single with predicate empty returns undefined', () => {
const res = single<number>([], { predicate: () => true });
expect(res).toBeUndefined();
});
test('Iterable#single predicate miss', () => {
const res = single([42], { predicate: (x) => x % 2 !== 0 });
expect(res).toBeUndefined();
});
test('Iterable#single no predicate hit', () => {
const res = single([42]);
expect(res).toBe(42);
});
test('Iterable#single predicate hit', () => {
const res = single([42], { predicate: (x) => x % 2 === 0 });
expect(res).toBe(42);
});
test('Iterable#single no predicate multiple throws error', () => {
expect(() => single([42, 45, 90])).toThrow();
});
test('Iterable#single with predicate multiple throws error', () => {
expect(() => single([42, 45, 90], { predicate: (x) => x % 2 === 0 })).toThrow();
});