|
1 | 1 | /** @prettier */
|
2 | 2 | import { expect } from 'chai';
|
3 |
| -import { of, Subject } from 'rxjs'; |
4 |
| -import { debounceTime, mergeMap } from 'rxjs/operators'; |
| 3 | +import { NEVER, of, Subject } from 'rxjs'; |
| 4 | +import { AnimationFrameAction } from 'rxjs/internal/scheduler/AnimationFrameAction'; |
| 5 | +import { AnimationFrameScheduler } from 'rxjs/internal/scheduler/AnimationFrameScheduler'; |
| 6 | +import { debounceTime, mergeMap, startWith } from 'rxjs/operators'; |
5 | 7 | import { TestScheduler } from 'rxjs/testing';
|
6 |
| -import { observableMatcher } from '../helpers/observableMatcher'; |
7 | 8 | import { VirtualTimeScheduler } from '../../src/internal/scheduler/VirtualTimeScheduler';
|
| 9 | +import { observableMatcher } from '../helpers/observableMatcher'; |
8 | 10 |
|
9 | 11 | /** @test {debounceTime} */
|
10 | 12 | describe('debounceTime', () => {
|
@@ -221,4 +223,21 @@ describe('debounceTime', () => {
|
221 | 223 |
|
222 | 224 | expect(results).to.deep.equal([1, 2]);
|
223 | 225 | });
|
| 226 | + |
| 227 | + it('should unsubscribe from the scheduled debounce action when downstream unsubscribes', () => { |
| 228 | + const scheduler = new AnimationFrameScheduler(AnimationFrameAction); |
| 229 | + |
| 230 | + expect(scheduler._scheduled).to.not.exist; |
| 231 | + expect(scheduler.actions).to.be.empty; |
| 232 | + |
| 233 | + const subscription = NEVER.pipe(startWith(1), debounceTime(0, scheduler)).subscribe(); |
| 234 | + |
| 235 | + expect(scheduler._scheduled).to.exist; |
| 236 | + expect(scheduler.actions.length).to.equal(1); |
| 237 | + |
| 238 | + subscription.unsubscribe(); |
| 239 | + |
| 240 | + expect(scheduler._scheduled).to.not.exist; |
| 241 | + expect(scheduler.actions).to.be.empty; |
| 242 | + }); |
224 | 243 | });
|
0 commit comments