Angular Jest tick not working for debounceTime on RxJS 7

1.6k Views Asked by At

I updated my angular application to Angular 13 and everything kept working fine. Then I updated RxJS from 6.6.0 to 7.4.0. After that some unittest failed.

Pseudo test:

it('should test some async', fakeAsync(() => {
  component.form.control.get('control').setValue('value')
  expect(component.somevalue).toBeNull();

  tick(999);
  fixture.detectChanges();
  expect(component.somevalue).toBeNull();

  tick(1);
  fixture.detectChanges();
  expect(component.somevalue).not.toBeNull();

}));

Pseudo code

form.control.get('control').valueChange.pipe(debounceTime(1000)).subscribe(x => this.someValue = x);

In the test the subscribe never gets a result so it seems debounceTime never continues. Any idea how to solve this?

I'm using

"@angular-builders/jest": "^13.0.2",
"jest": "27.4.3",
"jest-preset-angular": "^11.0.1",
1

There are 1 best solutions below

0
On

Seems like this is an issue. https://github.com/angular/angular/issues/44351. Though not ideal, this works for now:

it('should test some async', async () => {
    await wait(999);
});

export const wait = (ms: number): Promise<any> => {
    return new Promise(resolve => setTimeout(resolve, ms));
};