AssertionError with tests in Angular using clock/tick with intercept #27420
Replies: 1 comment 1 reply
-
@halbekanne thanks for posting your question. You should not need to use import { AppComponent } from './app.component';
describe('App', () => {
it('displays data from the server twice', () => {
cy.intercept('GET', 'https://yesno.wtf/api', {
body: {
answer: 'Apple',
}
}).as('apple');
cy.mount(AppComponent);
cy.get('.container').contains('Apple');
cy.intercept('GET', 'https://yesno.wtf/api', {
body: {
answer: 'Banana',
}
}).as('banana');
// you can also wait for requests to resolve by using `cy.wait()` and the `intercept` `alias`.
cy.wait('@apple')
cy.wait('@banana')
cy.get('.container').contains('Banana');
});
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
As I am very new to Cypress, I'm not sure if this is a (known) bug or if I'm doing something wrong.
Consider the following scenario. My component:
interval(1000)
)Now in the 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.
I did this using
cy.clock()
andcy.tick(1000)
in order to control and pass time. This is a minimal example test:When I run this test with Chrome, I get the following error: "AssertionError: Timed out retrying after 4000ms: Expected to find content: 'Banana' within the element: <div.container> but never did."
When I open Cypress in Chrome I can see that the request has been correctly mocked and is returning 'Banana' with the second call, at least it seems that way. The viewport still displays "Apple".
It's probably a problem with my thinking and inexperience with Cypress that I can't get behind why this isn't working.
A minimal example repository can be found here.
Beta Was this translation helpful? Give feedback.
All reactions