From 2101b10e2bccb6e493159935f0580d3839462d1a Mon Sep 17 00:00:00 2001 From: "Jalal.Fathi" Date: Thu, 25 Apr 2019 18:32:52 +0200 Subject: [PATCH] Fix visit command --- README.md | 5 ++++- commands.js | 9 ++++----- cypress-daywalker.js | 1 - example/index.html | 1 - 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 123c06f..eb75d39 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,9 @@ import 'cypress-daywalker/commands' ``` ## Usage + +The daywalker script gets injected when visiting a page via `cy.visit()`. + [Example](https://github.com/JaySunSyn/cypress-daywalker/blob/master/example/cypress/integration/example.spec.js) Some custom commands: @@ -25,4 +28,4 @@ cy.get('paper-button').dispatch(new MouseEvent('click')) cy.get('paper-input').setProp('moto moto') cy.get('paper-input').setProp('Question', 'label') -``` +``` \ No newline at end of file diff --git a/commands.js b/commands.js index ad0a2e8..a8e04e6 100644 --- a/commands.js +++ b/commands.js @@ -247,20 +247,19 @@ Cypress.Commands.overwrite('should', (...args) => { return attachAndReturnOriginalFn(...args); }); -Cypress.Commands.overwrite('visit', (...args) => { +Cypress.Commands.overwrite('visit', (originalFn, url, options, nodeModulesBase = '/node_modules/') => { Cypress.log({ displayName: 'DAYWALKER VISIT', - message: ${args[1]}, + message: url, }); cy.on('window:before:load', (w) => { const script = w.document.createElement('script'); - script.src = '/node_modules/cypress-daywalker/cypress-daywalker.js'; + script.src = `${nodeModulesBase}cypress-daywalker/cypress-daywalker.js`; w.document.querySelector('head').appendChild(script); }); - const originalFn = args.shift(); - return originalFn(...args); + return originalFn(url, options); }); Cypress.Commands.add('setProp', { prevSubject: true }, (subject, value, prop = 'value') => { diff --git a/cypress-daywalker.js b/cypress-daywalker.js index 217b9f3..81d04d8 100644 --- a/cypress-daywalker.js +++ b/cypress-daywalker.js @@ -122,7 +122,6 @@ .filter(element => { const parent = element.parentNode; const classList = (parent.classList && Array.from(parent.classList)) || []; - if (parentSelectorType.id) { return parent.id === parentSelectorType.id; } diff --git a/example/index.html b/example/index.html index ed72678..866a229 100644 --- a/example/index.html +++ b/example/index.html @@ -5,7 +5,6 @@ Daywalker -