Skip to content

Commit

Permalink
Fix visit command
Browse files Browse the repository at this point in the history
  • Loading branch information
JaySunSyn committed Apr 25, 2019
1 parent 178513a commit 2101b10
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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')
```
```
9 changes: 4 additions & 5 deletions commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') => {
Expand Down
1 change: 0 additions & 1 deletion cypress-daywalker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Daywalker</title>
<script src="./node_modules/cypress-daywalker/cypress-daywalker.js"></script>
<script type="module" src="src/my-element.js"></script>
</head>
<body>
Expand Down

0 comments on commit 2101b10

Please sign in to comment.