forked from ReactiveX/IxJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatcherror-spec.ts
More file actions
40 lines (33 loc) · 1.17 KB
/
Copy pathcatcherror-spec.ts
File metadata and controls
40 lines (33 loc) · 1.17 KB
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
36
37
38
39
40
import { jest } from '@jest/globals';
import '../iterablehelpers';
import { first, from, of, range, sequenceEqual, single, throwError } from 'ix/iterable/index.js';
import { catchError } from 'ix/iterable/operators/index.js';
test('Iterable#catchError error catches', () => {
const err = new Error();
const res = single(
throwError(err).pipe(
catchError((e: Error) => {
expect(e).toEqual(err);
return of(42);
})
)
);
expect(42).toBe(res);
});
test('Iterable#catchError no error misses', () => {
const xs = range(0, 10);
const res = xs.pipe(catchError((_: Error) => of(42)));
expect(sequenceEqual(res, xs)).toBeTruthy();
});
test('Iterable#catchError source and handler types are composed', () => {
const xs = range(0, 10);
const res = xs.pipe(catchError((_: Error) => of('foo')));
expect(sequenceEqual(res, xs)).toBeTruthy();
});
test('Iterable#catchError calls return() on source iterator when stopped early', () => {
const xs = range(0, 10)[Symbol.iterator]();
const returnSpy = jest.spyOn(xs, 'return');
const res = from(xs).pipe(catchError((_: Error) => from([])));
first(res);
expect(returnSpy).toHaveBeenCalled();
});