You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Order of triggers of before:response intercept lifecyle is the same as the request lifecycle when having multiple interceptors of the same endpoint
#29733
I noticed that when having multiple interceptors of the same api (lets say A, B, C) and having a RouteHandler on each of them as follows
cy.intercept('<url>',req=>{console.log('req A')req.on('before:response',res=>{console.log('res A')// do something with response})})
The order of execution of the before:response handlers is the same as the outgoing request so:
req -> C -> B -> A
res -> C -> B -> A
Whereas I would expect the order of the response to be in reverse for the response handler.
Is this the expected behavior (if not I can open an issue)?
Overall I am aiming to build a setup where you use multiple interceptors of a url to define a top to bottom structure of the final interceptor to be used in a test. So for example have a base interceptor in a beforeEach of a describe block and then intercept the same url in the test with the option to modify the response of the previous interceptor instead of creating a new one.
The above code snippet was how I envisioned it to work but due to the order being reversed it doesn't really work out. Is such a behavior achievable in another way?
Here is a full reproducible code snippet (note: the test is for angular component tests but I imagine the same behavior occurs in E2E and component tests of other frameworks):
it.only('should be a good example :D',()=>{cy.intercept('http://localhost:4200/interesting-path',{first: 5})cy.intercept('http://localhost:4200/interesting-path',req=>{console.log('req A')req.on('before:response',res=>{console.log('res A')// do something with response})})cy.intercept('http://localhost:4200/interesting-path',req=>{console.log('req B')req.on('before:response',res=>{console.log('res B')// do something with response})})cy.intercept('http://localhost:4200/interesting-path',req=>{console.log('req C')req.on('before:response',res=>{console.log('res C')// do something with response})})cy.mount(AppComponent,{imports: [AppModule]}).then(()=>fetch('http://localhost:4200/interesting-path'))});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I noticed that when having multiple interceptors of the same api (lets say A, B, C) and having a RouteHandler on each of them as follows
The order of execution of the before:response handlers is the same as the outgoing request so:
req -> C -> B -> A
res -> C -> B -> A
Whereas I would expect the order of the response to be in reverse for the response handler.
Is this the expected behavior (if not I can open an issue)?
Overall I am aiming to build a setup where you use multiple interceptors of a url to define a top to bottom structure of the final interceptor to be used in a test. So for example have a base interceptor in a beforeEach of a describe block and then intercept the same url in the test with the option to modify the response of the previous interceptor instead of creating a new one.
The above code snippet was how I envisioned it to work but due to the order being reversed it doesn't really work out. Is such a behavior achievable in another way?
Here is a full reproducible code snippet (note: the test is for angular component tests but I imagine the same behavior occurs in E2E and component tests of other frameworks):
Beta Was this translation helpful? Give feedback.
All reactions