Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Commit

Permalink
[bugfix] Handle native RegExp route URIs correctly
Browse files Browse the repository at this point in the history
Fixes #4
  • Loading branch information
mpetrovich committed Dec 24, 2019
1 parent 28835c7 commit 03c04b2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
8 changes: 7 additions & 1 deletion cypress/integration/navigation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ When I navigate to "actions"
Then I should be on "/cypress/pages/actions.html"


Scenario: Can assert to be on the current page by page name
Scenario: Can assert to be on the current page by page name when the page URI is a relative path
---
When I navigate to "assertions"
Then I should be on "assertions"


Scenario: Can assert to be on the current page by page name when the page URI is a regex
---
When I navigate to "assertions"
Then I should be on "any page"


Scenario: Can assert to be on the current page by page path string
---
When I navigate to "assertions"
Expand Down
1 change: 1 addition & 0 deletions cypress/support/step_definitions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ addSteps({
assertions: "/cypress/pages/assertions.html",
"input actions": "/cypress/pages/actions-inputs.html",
"input assertions": "/cypress/pages/assertions-inputs.html",
"any page": /cypress\/pages\//,
},
steps: {
"I double-click {element}": function(element, table, { options }) {
Expand Down
18 changes: 9 additions & 9 deletions src/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const { getElementOptions } = require("./index")

module.exports = {
/*
Actions
*/
Actions
*/

"I navigate to {route}": function(route, table, { routes }) {
cy.visit(routes[route] || route)
Expand Down Expand Up @@ -58,26 +58,26 @@ module.exports = {
},

/*
Assertions
*/
Assertions
*/

"I should be on {route}": function(route, table, { routes }) {
let path = routes[route] || route
const isRegexPath = path.startsWith("/") && path.endsWith("/")

if (isRegexPath) {
const isRegexStringPath = typeof path === "string" && path.startsWith("/") && path.endsWith("/")
if (isRegexStringPath) {
path = new RegExp(path.slice(1, -1))
}

let comparator = path instanceof RegExp ? "match" : "eq"
const comparator = path instanceof RegExp ? "match" : "eq"
cy.location("pathname").should(comparator, path)
},

"I should not be on {route}": function(route, table, { routes }) {
let path = routes[route] || route
const isRegexPath = path.startsWith("/") && path.endsWith("/")

if (isRegexPath) {
const isRegexStringPath = typeof path === "string" && path.startsWith("/") && path.endsWith("/")
if (isRegexStringPath) {
path = new RegExp(path.slice(1, -1))
}

Expand Down

0 comments on commit 03c04b2

Please sign in to comment.