Skip to content
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

Multiple requests to the same URL with different responses #1

Open
joaomilho opened this issue May 25, 2018 · 6 comments
Open

Multiple requests to the same URL with different responses #1

joaomilho opened this issue May 25, 2018 · 6 comments

Comments

@joaomilho
Copy link

Hey! First of all, thanks for the amazing work.

One common use case is multiple requests to the same non idempotent endpoint returning different responses. Do you have any idea on how to deal with that?

@paulgv
Copy link
Contributor

paulgv commented May 26, 2018

Hi @joaomilho !
That's an interesting point! I'm not sure exactly what's the right way to approach this use case but I guess this example could be improved by generating ID's for each request that's made in record mode, this would allow you to store multiple responses for a single endpoint.
Then in stubbed mode, you could implement some advanced logic to stub requests by passing a callback to cy.route() where you could dynamically select the response you want to send back.
What do you think? Let me know if you make any progress on this!

[edit] Actually, passing a callback to cy.route() might not provide that much flexibility, maybe a more "brute-force" approach would be to override requests' URLs to make them unique even when they point to the same endpoint?

@joaomilho
Copy link
Author

No, so far I didn't. I think there's no way around this while cypress doesn't have a dynamic route itself, as you say.

@joenguyenalogent
Copy link

joenguyenalogent commented Jul 12, 2019

Ever find a good solution for this? I tried https://github.com/scottschafer/cypressautomocker but wonder if it works well with Angular.

UPDATE: I think it also does not handle multiple calls to the same url/method with different responses in subsequent calls. It is overwritten by and only returns the last response it seems.

@paulgv
Copy link
Contributor

paulgv commented Jul 12, 2019

I would expect a Cypress plugin to work equally whatever the framework you're using for your app.

Maybe try out this plugin by @Nanciee https://github.com/Nanciee/cypress-autorecord

I haven't tried any of these but surely they are worth a shot!

@Nanciee
Copy link

Nanciee commented Jul 13, 2019

Ahh definitely encountered the same challenge when building cypress-autorecord. I found a messy solution for it that produces a silent CypressError but it does work! I talk a little bit about it here: Nanciee/cypress-autorecord#5 and have recently tested it again to make sure that it is still working.

@chauey
Copy link

chauey commented Jul 14, 2019

I think cypressautomocker replaced the xhr object with a fake one and didn't implement certain hooks like "addEventListener" so it broke Angular's http codes.

I asked about cypress-autorecord's issue about multiple calls to the same url/method w diff responses here: Nanciee/cypress-autorecord#9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants