Custom Command
Explore how to create custom commands in Cypress to streamline UI integration testing by stubbing backend interactions and managing JWT tokens. Understand how to simulate authentication without a working backend for faster, reliable tests.
We'll cover the following...
We'll cover the following...
Overview
As we have created a custom signup command for the E2E tests, we should also create an authentication command for the UI Integration Tests too. It will be way far simpler because we do not need a real signup/authentication, we just need the front-end to think that it’s authenticated.
We must set the jwt token into the local storage. Let’s write the authenticateIntegration custom command:
authenticateIntegration custom command.
Where can we get a valid jwt? From the signup.json fixture!
File: cypress/fixtures/users/signup.json
{
"user": {
"username": "tester",
"email": ...