-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Angular component tests don't correctly handle time with cy.clock() #27602
Comments
@halbekanne did you find a way to solve your issue. I'm running into the same issue with cypress fake timers and rxjs interval. |
@tomalaforge sadly that's not the case. I found a rather tedious workaround: create an abstraction layer for timers (I created a timer service), use it to replace the real timer with a fake one (e.g. a subject that you can call "next()" on), then find a way to call this fake timer from the Cypress test (e.g. define a function in the global window object that calls the next() function). That's the best I could come up with. I'm pretty sure it's not meant to work like that and that there should be an actual solution, because working with timers or intervals in Angular is not an uncommon scenario. |
Thanks for your answer. But for sure, that's not the best solution, but the temporary workaround 👍 |
@halbekanne , we also had issues with the For us, in order to re-render the UI, we had to:
Maybe the same thing will work in Angular also, if you restore the clock before making the UI assertions 🤔 |
@mpavel tried both workarounds and none worked in case of Angular Component Tests. 🤷 |
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided. |
This issue has been closed due to inactivity. |
Current behavior
Consider the following scenario. My Angular component:
Now in the component test I mocked calls to the backend that return something different after each call to test that the webpage gets updated with new data if its available on the server. It is a similar testing setup as it has been described in this blog post from Cypress.
As suggested in the blog post, I did this using
cy.clock()
andcy.tick(1000)
in order to control and pass time.When I run this test with Chrome, it doesn't update the component with the new data and I get the following error: "AssertionError: Timed out retrying after 4000ms: Expected to find content: 'Banana' within the element: <div.container> but never did."
In the example repository below, the Angular component uses RxJS interval() in order to fetch repeatedly, but other methods of setting up a timed fetch like
window.setInterval()
also doesn't seem to work.Desired behavior
The test should run successfully using
cy.clock()
andcy.tick()
using the mocked data and the Angular component should update with the new data.Test code to reproduce
Example Angular Component:
Example Component Test:
Example Repo with both files: https://github.com/halbekanne/cy-ng-intercept-rxjs-minimal-example
Cypress Version
12.17.2
Node version
v18.12.1
Operating System
macOS 13.3.1
Debug Logs
No response
Other
No response
The text was updated successfully, but these errors were encountered: