-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Stop a POST request from sending if tests fail #3847
Comments
Hey Tasha, I believe this isn't possible because tests are run after the request completes execution. You can notice that because inside the test cases you have access to the response object - hence, the request was already dispatched. Maybe you can describe your use case in more detail - there might be better-suited alternatives. |
Ah okay - I think that answers my question. Unfortunate ! I can try and elaborate on my issue a little more / on what I'm after. Here's an example;
with the JSON body being
I hope this is making sense so far ! I am seeing if there is any way we can stop the request from posting if any of my script test fails. Perhaps if there is a way to force an exception thrown while tests are run so the request doesn't send through the data? No worries if not, just wanted to check here instead of trying to spend days trying to code something that doesn't exist as functionality in Bruno. |
Hey @Tasha53505 , it sounds like you could validate that input in the pre-request script - check out the documentation. There, you have access to PS: Even though you can validate the input in the pre-request script, I'd advise doing that at the server side. As you described yourself, if the user sends "invalid" data somehow, that invalid data will be saved in the server side. The client shouldn't be the sole responsible for ensuring input validity. |
Thanks for this ! This is what I'm after. |
I have checked the following:
Describe the feature you want to add
Is there a way to already do this, or a work around? Perhaps something in the pre-request or post-request? Where if any of the tests written fail that it stops the response from passing through?
Mockups or Images of the feature
i.e
if(bru.tests === fail()) {
stop();
}
The text was updated successfully, but these errors were encountered: