【发布时间】:2019-10-07 15:48:11
【问题描述】:
我正在尝试使用debounceTime (rxjs) 为Angular 应用程序中的功能编写单元测试。并使用fakeAsync 进行异步测试。
即使我没有设置tick() 或设置像tick(500) 这样的小间隔,它看起来在测试中debounceTime 也会立即得到解决。
例如使用 delay(1000) 而不是 debounceTime(1000) fakeAsync 可以正常工作。
测试:
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
【问题讨论】:
标签: angular rxjs jasmine debounce