tick and fakeAsync doesn't work well in Angular 13 with rxjs 7 debounceTime
See original GitHub issueWhich @angular/* package(s) are the source of the bug?
core
Is this a regression?
Yes
Description
I upgraded to angular 13 and then tried upgrading rxjs to 7. The problem is it seems rxjs has changed the way the debounceTime operator works: https://rxjs.dev/6-to-7-change-summary#debouncetime. Because of this a lot of my tests now fail because the fakeasync scope and debounceTime don’t work well when the debounceTime is set up outside of a fakeAsync scope. If you run the test in this file: https://github.com/bgerstle-quot/debounceTest/blob/master/src/app/app.component.spec.ts the first test passes and the second fails.
Please provide a link to a minimal reproduction of the bug
https://github.com/bgerstle-quot/debounceTest/blob/master/src/app/app.component.spec.ts
Please provide the exception or error you saw
No response
Please provide the environment you discovered this bug in (run ng version
)
Angular CLI: 13.0.4
Node: 16.13.0
Package Manager: yarn 1.22.5
OS: linux x64
Angular: 13.0.3
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1300.4
@angular-devkit/build-angular 13.0.4
@angular-devkit/core 13.0.4
@angular-devkit/schematics 13.0.4
@angular/cli 13.0.4
@schematics/angular 13.0.4
rxjs 7.4.0
typescript 4.4.4
Anything else?
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:35
- Comments:18 (7 by maintainers)
Top Results From Across the Web
Angular Jest tick not working for debounceTime on RxJS 7
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.
Read more >Testing Input with “debounceTime” using 'tick()'— Karma ...
I will try to explain the working of tick() using an Input element. ... with “debounceTime” using 'tick()'— Karma-Jasmine Angular Testing.
Read more >fakeAsync - Angular
Wraps a function to be executed in the fakeAsync zone: ... Timers are synchronous; tick() simulates the asynchronous passage of time.
Read more >Angular Debouncetime Rxjs Testing - StackBlitz
https://github.com/angular/angular/issues/25457 https://medium.com/front-end-tricks/testing-with-fakeasync-in-angular-d7d0550994a4.
Read more >Debouncing Jasmine - Answers I Couldn't Find Anywhere Else
I have a typeahead control that uses debounceTime (from rxjs) to wait 250 ... fakeAsync, TestBed, tick } from '@angular/core/testing';
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I moved the
detectChanges
into the tests and that wasn’t enough. What did do it was changing thebeforeEach
into a callable function and then just running it at the start of each test. You can see what I’m talking about on this branch. It’s definitely a usable workaround, but not ideal. I also tried moving thefakeAsync
to thedescribe
, but causes an exception, which probably makes sense, but still prevents me from using thebeforeEach
Angular consumes RxJS andfakeAsync
is an angular function; therefore, I would argue that it is an Angular bug, without a fix, I can’t use thebeforeEach
the way Angular intends it to be used.Is there a plan to solve this or should we learn to live with it? Or should we consider it an issue with rxjs instead of Angular? 🤔
I agree with @ToelliJ; it doesn’t make sense to revise the component code to make the test pass 😐