Skip to content

Commit 76e43f3

Browse files
test(throttleTime): test leading and trailing enabled
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
1 parent 1dbbafa commit 76e43f3

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

spec/operators/throttleTime-spec.ts

+34-6
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,44 @@ describe('throttleTime operator', () => {
141141
});
142142

143143
describe('throttleTime(fn, { leading: true, trailing: true })', () => {
144-
asDiagram('throttleTime(fn, { leading: true, trailing: true })')('should immediately emit the first and last values in each time window', () => {
145-
const e1 = hot('-a-xy-----b--x--cxxx--|');
146-
const e1subs = '^ !';
147-
const t = time( '----| ');
148-
const expected = '-a---y----b---x-c---x-|';
144+
asDiagram('throttleTime(fn, { leading: true, trailing: true })')('should immediately emit the first and last values in each time window', () => {
145+
const e1 = hot('a123b12-c-23d-2-ef---|');
146+
const t = time('----| ');
147+
const expected = 'a---b---c---d---e---f|';
148+
149+
const result = e1.pipe(throttleTime(t, rxTestScheduler, { leading: true, trailing: true }));
150+
151+
expectObservable(result).toBe(expected);
152+
});
153+
154+
it('should immediately emit the first value in each time window', () => {
155+
const e1 = hot('-a---x------b|');
156+
const t = time('----| ');
157+
const expected = '-a---x------b|';
158+
159+
const result = e1.pipe(throttleTime(t, rxTestScheduler, { leading: true, trailing: true }));
160+
161+
expectObservable(result).toBe(expected);
162+
});
163+
164+
it('should emit the last throttled value when complete', () => {
165+
const e1 = hot('-x--|');
166+
const t = time('----|');
167+
const expected = '----(x|)';
168+
169+
const result = e1.pipe(throttleTime(t, rxTestScheduler, { leading: false, trailing: true }));
170+
171+
expectObservable(result).toBe(expected);
172+
});
173+
174+
it('should emit both simple leading and trailing', () => {
175+
const e1 = hot('-a-b------------------|');
176+
const t = time('----| ');
177+
const expected = '-a---b----------------|';
149178

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

152181
expectObservable(result).toBe(expected);
153-
expectSubscriptions(e1.subscriptions).toBe(e1subs);
154182
});
155183

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

0 commit comments

Comments
 (0)