Skip to content

Commit

Permalink
test(throttleTime): test leading and trailing enabled
Browse files Browse the repository at this point in the history
Test for double emission with leading and trailing enabled.
Also add more tests for leading and trailing enabled.

Double emission problem:
source:   a123b12-c-23d-2-ef---
expected: a---b---c---d---e---f
actual:   a---b1---c2---2-e---f
  • Loading branch information
MatthiasKunnen committed Jul 24, 2019
1 parent af20916 commit 90f7013
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions spec/operators/throttleTime-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,44 @@ describe('throttleTime operator', () => {
});

describe('throttleTime(fn, { leading: true, trailing: true })', () => {
asDiagram('throttleTime(fn, { leading: true, trailing: true })')('should immediately emit the first and last values in each time window', () => {
const e1 = hot('-a-xy-----b--x--cxxx--|');
const e1subs = '^ !';
const t = time( '----| ');
const expected = '-a---y----b---x-c---x-|';
asDiagram('throttleTime(fn, { leading: true, trailing: true })')('should immediately emit the first and last values in each time window', () => {
const e1 = hot('a123b12-c-23d-2-ef---|');
const t = time('----| ');
const expected = 'a---b---c---d---e---f|';

const result = e1.pipe(throttleTime(t, rxTestScheduler, { leading: true, trailing: true }));

expectObservable(result).toBe(expected);
});

it('should immediately emit the first value in each time window', () => {
const e1 = hot('-a---x------b|');
const t = time('----| ');
const expected = '-a---x------b|';

const result = e1.pipe(throttleTime(t, rxTestScheduler, { leading: true, trailing: true }));

expectObservable(result).toBe(expected);
});

it('should emit the last throttled value when complete', () => {
const e1 = hot('-x--|');
const t = time('----|');
const expected = '----(x|)';

const result = e1.pipe(throttleTime(t, rxTestScheduler, { leading: false, trailing: true }));

expectObservable(result).toBe(expected);
});

it('should emit both simple leading and trailing', () => {
const e1 = hot('-a-b------------------|');
const t = time('----| ');
const expected = '-a---b----------------|';

const result = e1.pipe(throttleTime(t, rxTestScheduler, { leading: true, trailing: true }));

expectObservable(result).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

it('should emit the value if only a single one is given', () => {
Expand Down

0 comments on commit 90f7013

Please sign in to comment.