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

  • SEARCH
  • Home
  • 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 8451621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:17:23+00:00 2026-06-10T11:17:23+00:00

I am using phantomjs to run jasmine test. My jasmine tests are using require

  • 0

I am using phantomjs to run jasmine test. My jasmine tests are using require around the describe blocks to ensure all the right modules are loaded.

My tests would not run because page.evaluate -> jasmine.getEnv().execute(); runs BEFORE requirejs finishes loading the modules.

I was wondering if anyone knows a real good way around this. I have an answer I’m going to post below but would love to compare notes via other answers. If yours is better, I will def pick it as answer obviously 🙂

  • 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-06-10T11:17:25+00:00Added an answer on June 10, 2026 at 11:17 am

    My solution, with jQuery available, is this:

    Load a config file before any of your tests run.

    var jasmine_deferreds = [];
    
    // Setup an event to fire on the document
    // I actually did this with native code rather than jquery because
    // I wanted to minimize jquery usage
    
    // ....
    
    // setTimeout so all files loaded after this will finish registering their requires
    setTimeout( function() {
    
      $.when.apply( null, jasmine_deferreds ).then( function() {
    
        // Fire event that was created
    
      });
    
    }, 5 );
    

    It’s up to you how you want to build up the array of deferreds and then resolve them. I essentially pushed to the array and then resolved when the require was done. I wrapped require with my own version that would know to resolve it upon completion automatically – so I don’t need to push and resolve manually in each test.

    Then in my phantom file I do this:

    page.evaluate ->
        mylistener = ( document ) -> jasmine.getEnv().execute();
        document.addEventListener( 'test_ready_event', mylistener, false);
    

    This makes it so I know all my require modules are loaded without having some arbitrary setTimeout that could be too short once I am loading too many files. The one setTimeout I’m using is safe because it’s only being used to fire after main callstack is done. It doesn’t really care about the time.

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

Sidebar

Related Questions

I'm using phantomjs with casperjs to run multiple tests and it looks like each
I have a few pure-JavaScript, client-side tests using PhantomJS. These I'd like to integrate
I trying to run my jamsine specs from command line using PhantomJs.exe. Here is
I am already using unit testing to ensure that all critical bits and pieces
I'm using PhantomJS page.evaluate() to do some scraping. My problem is that the code
Using the Redis info command, I am able to get all the stats of
I'm using PhantomJS with jQuery and I'm wondering if it's possible to capture an
I have a PhantomJS/CasperJS script which I'm running from within a node.js script using
I cant understand how to using proxies in phantomjs, i tried phantomjs example.js --proxy=ip:port
Using JQuery, how do I select all elements with class x within an element

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.