Skip to content

Commit

Permalink
Overwrite visit command
Browse files Browse the repository at this point in the history
Dynamically inject daywalker script.
  • Loading branch information
JaySunSyn authored Apr 25, 2019
1 parent d8fa0cc commit a8e9084
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,22 @@ Cypress.Commands.overwrite('should', (...args) => {
return attachAndReturnOriginalFn(...args);
});

Cypress.Commands.overwrite('visit', (...args) => {
Cypress.log({
displayName: 'DAYWALKER VISIT',
message: ${args[1]},
});

cy.on('window:before:load', (w) => {
const script = w.document.createElement('script');
script.src = '/node_modules/cypress-daywalker/cypress-daywalker.js';
w.document.querySelector('head').appendChild(script);
});

const originalFn = args.shift();
return originalFn(...args);
});

Cypress.Commands.add('setProp', { prevSubject: true }, (subject, value, prop = 'value') => {
const element = subject[0];
Cypress.log({
Expand Down Expand Up @@ -288,4 +304,4 @@ Cypress.Commands.add('dispatch', { prevSubject: true }, (subject, event, options
element.dispatchEvent(e, options)
};
return subject;
});
});

0 comments on commit a8e9084

Please sign in to comment.