From 7f033090810682914d835d22b936d06336b021d8 Mon Sep 17 00:00:00 2001 From: Nick Cook <90210642+they-call-me-foo@users.noreply.github.com> Date: Sun, 21 Aug 2022 02:38:50 +0100 Subject: [PATCH] Add cy.visitRoute() command. Update README --- README.md | 18 ++++++++++++++++++ src/stubs/support/laravel-commands.js | 13 +++++++++++++ 2 files changed, 31 insertions(+) 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. *