2

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",
Robin Dijkhof
  • 18,665
  • 11
  • 65
  • 116
  • are you using jasmine marbles (or jest-marbles) somwhere on your tests? – Some random IT boy Dec 07 '21 at 16:20
  • @SomerandomITboy no, I am not. I am only using the dependencies described above. – Robin Dijkhof Dec 07 '21 at 16:40
  • I mentioned because we're using jasmine-marbles (we use jasmine) and turned out that we had to `npm install jasmine-marbles@latest` in order to get the proper testing version of that due to that the developer had not published the latest version for `jasmine-marbles` due to most people not being in Angular 13 yet. [See this post](https://github.com/CodeSequence/jasmine-marbles/issues/83). Perhaps it's the same forr the underlying dependencies for jest. – Some random IT boy Dec 07 '21 at 18:26
  • 7
    Most likely the problem is that rxjs has changed the way the debounceTime operator works. There is an open issue in angular repo to fix this bug: https://github.com/angular/angular/issues/44351 – Dimnox Dec 08 '21 at 09:31

1 Answers1

1

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));
};
Robin Dijkhof
  • 18,665
  • 11
  • 65
  • 116