-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Scheduler.flush throws unclear error when actions is empty (cannot read property 'execute' of undefined) #4690
Comments
Are you able to effect this error without an explicit call to |
Not that I am aware of. My specific use case is flushing async schedulers during tests. Otherwise I need to mock the behavior of Window.requestAnimationFrame in tests. My current workaround is just to check the number of actions before calling requestAnimationFrame which works but is less than ideal. |
I don't think this is a bug. I think you should be using the You might also want to read this: https://ncjamieson.com/testing-with-fake-time/ |
I've had a quick look at this and I cannot reproduce the problem. And I cannot see any obvious flaw in the code. Note that Without more context, there is nothing further that I can do. I note that version 6.4.x is mentioned in the issue description. However, there is a reference to version 5.4.1 source. And I have no idea of the version to which you are attributing the reported Bugsnag failures. |
Thanks for the heads up! I did not know about this scheduler and it seems really cool! Unfortunately TestScheduler, as far as I can tell, will cause an infinite loop when running https://stackblitz.com/edit/rxjs-kkntbc?file=index.ts Whether or not there is a workaround to my specific problem with using TestScheduler, I still think it might be useful to prevent future issues if one of the following changes was made:
Any of which I would be more than happy to contribute. |
You might be better off testing using fake time. Have a look at https://ncjamieson.com/testing-with-fake-time/ Regarding the documentation, it's TSDoc - not JSDoc - and Regarding the public interface for schedulers, it's this: https://rxjs.dev/api/index/interface/SchedulerLike Anything not in that interface is an implementation detail. |
For what it's worth, Jasmine and Jest do not support faking requestAnimationFrame with their built-in fake time libraries. Sinon does, but switching to Sinon in order to take advantage of the animationFrameScheduler is not within scope of what I am hoping to accomplish. I initially ran into some issues manually mocking requestAnimationFrame and having it work as expected with the animationFrameScheduler, but I will file a different bug for that when I next run into this issue. I do not entirely agree that it is currently intuitive that SchedulerLike is the public API for animationFrameScheduler and I still think the code would benefit from some sort of clearer communication when the above error is thrown, but that's my own opinion. At the very least this issue will exist if someone else encounters this error. Regardless, I appreciate your work on this project: thank you for helping to maintain rxjs! I am fine with closing this issue (unless you wanted additional information from @decafdennis) |
My concern is that the issue is not reproducible and that there are historical issues - AFAICT - in some browsers with Regarding testing, a polyfill is used in this project to allow the scheduler to be tested in Node. Such an approach should work fine with fake time without Sinon. |
Bug Report
Current Behavior
Calling .flush() on a scheduler (e.g. animationFrameScheduler) with no pending actions causes an unclear exception to be thrown:
Reproduction
Expected behavior
Either one of:
Environment
Possible Solution
See expected behavior. This appears to affect all schedulers that have this
do while
loop without verifying that a valid action has beenshift
'd off ofthis.actions
This may be working as intended (and no change desired for performance reasons) in which case just having this issue open and google-able would provide additional documentation
Additional context/Screenshots
#2697 Appears to have been the same issue given their stacktrace: https://github.com/ReactiveX/rxjs/blob/5.4.1/src/scheduler/AsapScheduler.ts#L17
A clearer error (or no error at all) would probably have pointed them in the right direction.
Happy to submit a fix myself if the desired behavior is defined.
The text was updated successfully, but these errors were encountered: