From 2db00163241ef0d5283b78e1b00808f60ac0f3e4 Mon Sep 17 00:00:00 2001 From: Matthias Kunnen Date: Wed, 13 Feb 2019 21:49:52 +0100 Subject: [PATCH 1/3] test(throttleTime): test single value with trailing enabled Test if throttleTime emits when only a single value is emitted from the source with leading enabled/disabled and trailing enabled. --- spec/operators/throttleTime-spec.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spec/operators/throttleTime-spec.ts b/spec/operators/throttleTime-spec.ts index fef0cd15b3..bbaab5153c 100644 --- a/spec/operators/throttleTime-spec.ts +++ b/spec/operators/throttleTime-spec.ts @@ -152,6 +152,16 @@ describe('throttleTime operator', () => { expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); }); + + it('should emit the first value if only a single one is given', () => { + const e1 = hot('-a--------------------|'); + const t = time('----| '); + const expected = '-a--------------------|'; + + const result = e1.pipe(throttleTime(t, rxTestScheduler, { leading: true, trailing: true })); + + expectObservable(result).toBe(expected); + }); }); describe('throttleTime(fn, { leading: false, trailing: true })', () => { @@ -178,5 +188,15 @@ describe('throttleTime operator', () => { expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); }); + + it('should emit the first value if only a single one is given', () => { + const e1 = hot('-a--------------------|'); + const t = time('----| '); + const expected = '-----a----------------|'; + + const result = e1.pipe(throttleTime(t, rxTestScheduler, { leading: false, trailing: true })); + + expectObservable(result).toBe(expected); + }); }); }); From 0cbbbaead06b4fa845ab35605250ab563273bd3e Mon Sep 17 00:00:00 2001 From: Matthias Kunnen Date: Wed, 13 Feb 2019 21:53:33 +0100 Subject: [PATCH 2/3] fix(throttleTime): fix single value with leading disabled, trailing enabled Emit single value with leading disabled, trailing enabled. Closes #2859 and #4491. --- src/internal/operators/throttleTime.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/internal/operators/throttleTime.ts b/src/internal/operators/throttleTime.ts index b5da87585c..5da1540c79 100644 --- a/src/internal/operators/throttleTime.ts +++ b/src/internal/operators/throttleTime.ts @@ -101,6 +101,9 @@ class ThrottleTimeSubscriber extends Subscriber { this.add(this.throttled = this.scheduler.schedule>(dispatchNext, this.duration, { subscriber: this })); if (this.leading) { this.destination.next(value); + } else if (this.trailing) { + this._trailingValue = value; + this._hasTrailingValue = true; } } } From 8a47065ab3ef5eb0cedcfbf2f78e979b4e1d6222 Mon Sep 17 00:00:00 2001 From: Nicholas Jamieson Date: Sat, 13 Apr 2019 15:11:47 +1000 Subject: [PATCH 3/3] chore: improve test descriptions And remove an asDiagram call made with the same argument. Signed-off-by: Matthias Kunnen --- spec/operators/throttleTime-spec.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/operators/throttleTime-spec.ts b/spec/operators/throttleTime-spec.ts index bbaab5153c..4e65054ae8 100644 --- a/spec/operators/throttleTime-spec.ts +++ b/spec/operators/throttleTime-spec.ts @@ -141,10 +141,10 @@ describe('throttleTime operator', () => { }); describe('throttleTime(fn, { leading: true, trailing: true })', () => { - asDiagram('throttleTime(fn, { leading: true, trailing: true })')('should immediately emit the first value in each time window', () => { + 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 t = time( '----| '); const expected = '-a---y----b---x-c---x-|'; const result = e1.pipe(throttleTime(t, rxTestScheduler, { leading: true, trailing: true })); @@ -153,7 +153,7 @@ describe('throttleTime operator', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - it('should emit the first value if only a single one is given', () => { + it('should emit the value if only a single one is given', () => { const e1 = hot('-a--------------------|'); const t = time('----| '); const expected = '-a--------------------|'; @@ -165,10 +165,10 @@ describe('throttleTime operator', () => { }); describe('throttleTime(fn, { leading: false, trailing: true })', () => { - asDiagram('throttleTime(fn, { leading: false, trailing: true })')('should immediately emit the first value in each time window', () => { + asDiagram('throttleTime(fn, { leading: false, trailing: true })')('should immediately emit the last value in each time window', () => { const e1 = hot('-a-xy-----b--x--cxxx--|'); const e1subs = '^ !'; - const t = time( '----| '); + const t = time( '----| '); const expected = '-----y--------x-----x-|'; const result = e1.pipe(throttleTime(t, rxTestScheduler, { leading: false, trailing: true })); @@ -177,10 +177,10 @@ describe('throttleTime operator', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - asDiagram('throttleTime(fn, { leading: false, trailing: true })')('should emit the last throttled value when complete', () => { + it('should emit the last throttled value when complete', () => { const e1 = hot('-a-xy-----b--x--cxx|'); const e1subs = '^ !'; - const t = time('----| '); + const t = time('----| '); const expected = '-----y--------x----(x|)'; const result = e1.pipe(throttleTime(t, rxTestScheduler, { leading: false, trailing: true })); @@ -189,7 +189,7 @@ describe('throttleTime operator', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - it('should emit the first value if only a single one is given', () => { + it('should emit the value if only a single one is given', () => { const e1 = hot('-a--------------------|'); const t = time('----| '); const expected = '-----a----------------|';