How to stub Inertia requests on Cypress? #1194
Unanswered
MtDalPizzol
asked this question in
Help
Replies: 1 comment
-
@MtDalPizzol Did you ever figure out how to handle this? |
Beta Was this translation helpful? Give feedback.
0 replies
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.
-
Hi, folks... I have just hit a problem trying to test my Laravel + Vue with Cypress.
I have a controller method that
return back()->withErrors([ 'custom_error' => 'yadayadayada'])
;In order to test a failure scenario in that controller, I thought of stubbing that request in Cypress. with
server
androute
to mimic a Inertia redirect response. Something in these lines:The problem here, clearly, is that stubbing the request prevents Cypress from hitting the Laravel server and, therefore, from flashing the errors to the session, causing the
http://localhost/
to be rendered normally, with no errors. This makes testing for an error scenario impossible if the app is written in the "Inertia way".So... Is there a recommendation on how to handle this?
The only workaround I came up with is not to
return back()->withErrors()
and instead justabort(400, 'yadayadayada')
and handle it in the old "Axios way". This would allow me to automatize my tests, but my code would become a weird mix of "Inertia and Axios" responses.Beta Was this translation helpful? Give feedback.
All reactions