-
Notifications
You must be signed in to change notification settings - Fork 2
/
map-last.spec.ts
32 lines (28 loc) · 1.13 KB
/
map-last.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
import {marbles} from 'rxjs-marbles';
import {mapLast} from './map-last';
describe('mapLast', () => {
it('should map the last value', marbles(m => {
const source = m.cold('a-b-c-d-|').pipe(mapLast(v => `!${v}!`));
const result = ' --a-b-c-(d|)';
m.expect(source).toBeObservable(result, {
a: 'a',
b: 'b',
c: 'c',
d: '!d!'
});
}));
it('should not emit any values if observable emits only one and never completes', marbles(m => {
const source = m.cold('a').pipe(mapLast(v => `!${v}!`));
m.expect(source).toBeObservable('');
}));
it('should not emit last value if observable never completes', marbles(m => {
const source = m.cold('a-b-c-d').pipe(mapLast(v => `!${v}!`));
const result = ' --a-b-c)';
m.expect(source).toBeObservable(result);
}));
it('should emit last value for single value and completes', marbles(m => {
const source = m.cold('a|').pipe(mapLast(v => `!${v}!`));
const result = '-(a|)';
m.expect(source).toBeObservable(result, {a: '!a!'});
}));
});