question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 6 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
canercandancommented, Apr 5, 2018

@brian-mann I am running into the same issue though I am using the last release of cypress v2.1.0:

Cypress.Commands.overwrite('visit', (visit, url, options) => {
  console.log('overwritten visit')
  return visit(url, {
    onBeforeLoad: (win) => {
      console.log('onBeforeLoad')
    },
  })
})

onBeforeLoad does not get triggered, thanks.

2reactions
RobbinHabermehlcommented, Oct 9, 2018

Unfortunately, this still isn’t working as of v3.0.3 @brian-mann.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found