Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6837551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:29:26+00:00 2026-05-26T23:29:26+00:00

Use case is this: I want to unit test (in browser, QUnit or something

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:29:27+00:00Added an answer on May 26, 2026 at 11:29 pm

    You could check this How far can you go with JavaScript testing? question.

    Selenium is indeed good and well-known, but I personally find it quite old and not so usable. I’d advise using Ghostbuster (see introduction), a headless Webkit running tests written in Javascript or Coffeescript.

    Your given test-case would be written as follows:

    phantom.test.root = "http://localhost/"     # or whatever your testing env's root
    
    phantom.test.add "Facebook login", ->       # this adds a test
      @get '/yourLoginPage', ->                 # relative to the previous root
        @body.click '#login-btn'
        @assertLocation "http://www.facebook.com/oauth/..."
        @succeed()                              # all tests must succeed
    

    🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My use case is this, I want to call out to a webservice and
I have this use case of an xml file with input like Input: <abc
The use case is some what like this: public class SomeClass : ICloneable {
I'm starting to use Mercurial on my web server (in this case MediaTemple's Grid).
How can I use output caching with a .ashx handler? In this case I'm
Use case: A does something on his box and gots stuck. He asks B
I'd like to run a unit test where a constant is slightly different than
I want to use php in console mode and create an environment to test
I'm writing a unit test for a Wicket WebPage. I want to fire up
I'm trying to unit test a custom model binder - specifically, I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.