This post is showing some examples that are pretty easy to add to any Laravel project that use Laravel Breeze. Here a login example: Take in mind that the default user factories from Laravel sets user password generated by factories as "password": describe('Authentication test', () => { it('tests a success manual authentication with the login form', () => { cy.visit(`/login`); cy.php(` App\\Models\\User::factory()->create(['email', 'john@doe.com']); `).then(user => { cy.get('input[type="email"]').type(user.email); cy.get('input[type="password"]').type('password'); }); cy.get('button[type="submit"]').click(); cy.location('pathname').should('equal', '/dashboard'); }); }); Enter fullscreen mode Some interesting ideas could be: #test-http-status-code Test http status code cy.request('http://localhost:8000/dashboard').then((response) => expect(response.status).to.eq(200)); Enter fullscreen mode #test-a-middleware Test a middleware // visit a url cy.visit('http://localhost:8000/dashboard'); // check the next url location cy.url().should('match', /login); Enter fullscreen mode Sometimes you require to test a larger workflow like logout and then check that some middleware works...

Or even better, use the PHP method or the login helper to test exactly the current user welcome message: cy.login({ email: 'john@doe.com', name: 'John Doe' }); cy.visit('/dashboard').contains('Welcome Back, John Doe'); Enter fullscreen mode
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners