onBeforeLoad does not work when overriding visit
See original GitHub issue- Operating System: osx
- Cypress Version: 0.20.0
- Browser Version: chrome 60
Is this a Feature or Bug?
Bug
Current behavior:
Commands.overwrite seems to break onBeforeLoad for visit command
Test code:
Cypress.Commands.add('visitRoute', (route) => {
cy.visit(route, {
onBeforeLoad(win) {
console.log('this will happen');
}
});
});
// However if I replace visitRoute with visit and the above with
Cypress.Commands.overwrite('visit', (visit, route) => {
console.log('this will happen');
visit(route, {
onBeforeLoad(win) {
console.log('this will not happen');
}
});
});
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Override Window.onbeforeOnLoad Message and perform ...
The answer simply is you cannot override the onbeforeUnLoad message. You can however do something with the message, for example: $(document).
Read more >stub | Cypress Documentation
cy.stub() is a utility function, and is not a Cypress command, ... can do this by stubbing functions inside the cy.visit() command onBeforeLoad...
Read more >Window: beforeunload event - Web APIs | MDN
The beforeunload event suffers from the same problems as the unload event. Especially on mobile, the beforeunload event is not reliably fired.
Read more >Stub Objects By Passing Them Via Window Property
We can do this in the onBeforeLoad callback of the cy.visit command. cypress/integration/override-spec.js. 1 2
Read more >Thread: Overriding onBeforeUnload dialog message
Re: Overriding onBeforeUnload dialog message. What code are you using? I'm not sure on how to solve the problem, but I'd like to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@brian-mann I am running into the same issue though I am using the last release of
cypress
v2.1.0
:onBeforeLoad
does not get triggered, thanks.Unfortunately, this still isn’t working as of
v3.0.3
@brian-mann.