-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest-marbles-tests.spec.ts
47 lines (41 loc) · 1.45 KB
/
jest-marbles-tests.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
36
37
38
39
40
41
42
43
44
45
46
47
import { cold, time, Scheduler } from 'jest-marbles';
import { of, from, timer } from 'rxjs';
import { take, catchError, delay } from 'rxjs/operators';
describe('jest-marbles tests', () => {
describe('of', () => {
it('should emit single value and immediately complete', () => {
expect(of([1, 2, 3])).toBeObservable(cold('(a|)', { a: [1, 2, 3] }));
});
});
describe('from', () => {
it('should emit all items of array and immediately complete', () => {
expect(from(['a', 'b', 'c'])).toBeObservable(cold('(abc|)'));
});
});
describe('timer', () => {
it('should emit after a given time and immediately complete', () => {
expect(timer(time('---|'), Scheduler.get())).toBeObservable(
cold('---(0|)')
);
});
it('using TestScheduler.run() should emit after a given time and immediately complete', () => {
Scheduler.get().run(() =>
expect(timer(time('---|'))).toBeObservable(cold('---(0|)'))
);
});
it('should emit periodically after a given delay and complete after 3 emits', () => {
expect(
timer(time('---|'), time('-|'), Scheduler.get()).pipe(take(3))
).toBeObservable(cold('---01(2|)'));
});
});
describe('catchError', () => {
it('should emit error message and complete', () => {
expect(
cold('--x#|', { x: 1 }, new Error('2')).pipe(
catchError(e => of(e.message))
)
).toBeMarble('--1(2|)');
});
});
});