Use case is this: I want to unit test (in browser, QUnit or something of the kind) a code run in a page. One of the things a page can do is to navigate away to another page. I have problem catching this event, because:
- beforeunload cannot stop the action (so the first navigation-away breaks my test)
- trying to redefine window.location or window.location.href with getter returning old value and spying setter is prohibited, too
I understand there are security reasons that disallow possibility to stop navigating away, but for development it is really useful to be able to do so.
Is there any possibility to do this (I have no direct control over test runner, so I can't just load the code in the iframe and let it navigate and then examine location of the iframe)?
EDIT: To be a little more specific: I want to test, whether, based on the logged/connected status from facebook (I use facebook-stub from github to mock fb), there is the right handler is installed on the login button (say, $('#login-btn')
), which by clicking navigates the page to facebook oauth dialog, server-flow (the details here are not important).
So I would like to be able to do this kind of thing:
// set up fb mock to not be connected
fbAsyncInit(); // simulate the startup of app
$('#login-btn').click();
equal(document.location.href, "http://www.facebook.com/oauth/...", "OAuth dialog not started.");
but if course, without actual navigation. How to do the test?