In this episode, we dive into testing validation errors in our end-to-end tests. While feature or unit tests are usually better for validation logic, sometimes you just need to check validation behavior through an actual browser flow. We'll walk through how to do that, step-by-step.
First, we create a test that checks if the app fails whenever a required field (like a task title) isn't provided. We mock a logged-in user, visit the create page, and immediately hit the submit button with missing input. When the validation error shows up, we assert its presence.
But what about when validation messages change? Hardcoding error messages is fragile because any text change breaks your test. So we explore two ways to make tests more reliable:
We finish up by showing how this approach continues to work even if you switch validation to a dedicated form request or customize your error messages. The idea: focus on the presence of validation feedback, not its exact wording. That way, your tests are less brittle and easier to maintain!