I'm trying to write unit test for function in Angular app with debounceTime (rxjs). And use fakeAsync for asynchronous testing.
And it looks that in test debounceTime gets resolved immediately even if I don't set tick() or set it with small interval like tick(500).
For example with delay(1000) instead of debounceTime(1000) fakeAsync works fine.
test:
describe('rr', () => {
it('should get Date diff correctly in fakeAsync with rxjs scheduler', fakeAsync(() => {
let result = null;
of ('hello').pipe(debounceTime(1000)).subscribe(v => { result = v; });
expect(result).toBeNull(); // But it is 'Hello' - debounceTime resolves immediately
tick(1000);
expect(result).toBe('hello');
...
}));
})
stackblitz: https://stackblitz.com/edit/angular-ohhi9e?file=src%2Fapp%2Fapp.component.spec.ts