diff --git a/README.md b/README.md index 8604012..0a0898b 100644 --- a/README.md +++ b/README.md @@ -340,6 +340,24 @@ test('it loads the team dashboard page using a named route', () => { }); }); ``` +There is also a wrapper command available called `cy.visitRoute()` which can be used to simplify the boilerplate in the above examples. + +```js +test('it loads the about page using a named route', () => { + cy.visitRoute('about'); +}); +``` + +and + + +```js +test('it loads the team dashboard page using a named route', () => { + cy.visitRoute('team.dashboard', { + parameters: { team: 1 } + }); +}); +``` Should you need to access the full list of routes for your application, use the `Cypress.Laravel.routes` property. diff --git a/src/stubs/support/laravel-commands.js b/src/stubs/support/laravel-commands.js index 9af6c64..b743e08 100644 --- a/src/stubs/support/laravel-commands.js +++ b/src/stubs/support/laravel-commands.js @@ -140,6 +140,19 @@ Cypress.Commands.overwrite('visit', (originalFn, subject, options) => { return originalFn(subject, options); }); +/** + * Visit the given route. + * + * @example cy.visitRoute('home'); + * cy.visitRoute('team', { parameters: { team: 1 } }); + */ + Cypress.Commands.add("visitRoute", (routeName, ...options) => { + return cy.visit({ + route: routeName, + ...options, + }); + }); + /** * Create a new Eloquent factory. *