cy.clock() and cy.tick() with Rxjs polling pattern using exhaustMap() #14833
Replies: 3 comments 1 reply
-
I was recently sent this and it may help:
If we can actually get a simple reproducible example of this polling behavior, we can try to find and document a solution. |
Beta Was this translation helpful? Give feedback.
-
Hi Murat, i think the problem is our “freezing” of the clock when loading the page which stops the rxjs from working - if there were a demo page showing the problem during a test like this it would be so good to debug this
…Sent from my iPhone
On Feb 2, 2021, at 15:02, Murat K Ozcan ***@***.***> wrote:
Thank you.
I will follow up when / if there is a deployment of the app - we cannot share the source code but test code is ok.
For the time being, inspired by this blog post we created a helper function to let Cypress have component access to the Angular app, without having to resort to changing the source code with this:
// your Angular component file
constructor( /* ... */ ) {
// if running inside Cypress tests, set the component
// @ts-ignore
if (window.Cypress) {
window.yourComponent = this;
}
}
Instead we utilize a helper function like this:
Cypress.Commands.add('component', (componentSelector: string) => {
let angular!: any;
return cy
.window()
.then((win) => (angular = (win as any).ng))
.then(() => cy.document())
.then((doc) => angular.getComponent(doc.querySelector(componentSelector)))
.then((component) => component)
.should('exist');
});
And then use it like this the test:
cy.component('your-component-selector').its('OurService.pollingFrequency').should('eq', 20000);
After cy.component('your-component-selector') you can do anything with the component.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Beta Was this translation helpful? Give feedback.
-
Sidenote: @kevinold this type of scenario (polling backends from the frontend) would be an interesting addition to the RWA. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In our other Angular apps we have used cy.clock() and tick() successfully.
We have a new Angular app in which we are polling an endpoint at 20 sec intervals using a Rxjs polling pattern. This value is set at
environment.ts
and read into a service. The polling pattern looks as such:Here are our attempts at testing the above polling code.
Beta Was this translation helpful? Give feedback.
All reactions