New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tick and fakeAsync doesn't work well in Angular 13 with rxjs 7 debounceTime #44351
Comments
The problem here is that the template is checked for changes outside of I don't see how this is an Angular bug, then. Since To make the tests work, you'd have to defer the change detection cycle into the |
I moved the |
@JoostK We have some of our test broken after update from ng12.1.1 to ng13.1.0. We use jest via Reduced an issue to such case test('smth', fakeAsync(() => {
const data = new Subject<void>();
const received = jest.fn();
data
.pipe(
// rate limiting, no more than 10 events per second
concatMap(update => concat(of(update), EMPTY.pipe(delay(100)))),
)
.subscribe(received);
expect(received).toHaveBeenCalledTimes(0);
data.next();
data.next();
expect(received).toHaveBeenCalledTimes(1);
tick(50);
expect(received).toHaveBeenCalledTimes(1);
tick(51);
expect(received).toHaveBeenCalledTimes(2);
})); results in
so it fails even before first in real tests we have stream initialisation separately in |
@JoostK added a reproduction with clean ng13 install
spec code same as above https://github.com/artaommahe/ng13-tick-issue/blob/master/src/app/app.component.spec.ts#L5. Worked fine with ng12.1 |
I encountered this after upgrading to ng13 and rxjs7 and found my tests were subscribing to the obs outside of a fakeAsync (in my beforeEach). I was able to resolve this by moving the subscription (literally the .subscribe call) into the individual test's body, wrapped in a fakeAsync. Maybe unrelated to other comments, but wanted to share one more thing to look for. |
@JoostK can someone look at this please? we have a reproduction with clean ng app above |
@artaommahe The |
@JoostK oh, thx. there is nothing about these changes here https://rxjs.dev/deprecations/breaking-changes 😕 |
+1 |
+1. Having the same issue with angular 13.2.2 |
@artaommahe, just like @JoostK mentioned, the |
+1 |
1 similar comment
This comment was marked as off-topic.
This comment was marked as off-topic.
You can find a notice on 6-to-7-change-summary. I had the same issue. I found out that you can fix the tests by changing the implementation from in example |
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 :| |
I also fixed this recently by moving my suite wide |
This worked for me... import { interval, of } from 'rxjs';
import * as rxjsOperators from 'rxjs/operators';
import { debounce } from 'rxjs/operators';
// in test suit setup...
jest.spyOn(rxjsOperators, 'debounceTime').mockImplementation((timeout) => debounce(() => interval(timeout))) |
Moving the code that subscribes to the observable within the |
Angular 15.1.0 |
ReactiveX/rxjs#6382 see rxjs this issue |
The workaround suggested by @bgerstle-quot worked for me as well (thank you!). But this was such an annoying issue as it does not happen for all the components. |
@pkozlowski-opensource we tried this strategy - but it wasn't correctly reporting failures for us: whatever expectations we put in the |
@ananthay I don't see this issue depending on Angular but on RxJs team. |
Which @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
)Anything else?
No response
The text was updated successfully, but these errors were encountered: