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 7715649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:26:23+00:00 2026-06-01T02:26:23+00:00

We have an immediate function in the file ‘mediator.js’ which adds a ‘mediator’ object

  • 0

We have an immediate function in the file ‘mediator.js’ which adds a ‘mediator’ object to the global namespace. This ‘mediator’ is the only global object we have.

Now we have many different unit-tests for the ‘mediator’ object. And we want each test to run in isolation – in other words, each test needs to start by invoking the immediate function to create a new clean mediator object.

The tests are written in Jasmine and we run them with both Chutzpah and JsTestDriver.

So how can I do this?

  • In Chutzpah, I could put each individual test into it’s own js file, and reference mediator.js in each test file
  • With JsTestDriver, I could need a config file for each test, which includes the mediator.js and the test file

We are also considering abandoning the immediate pattern, and have a constructor function to create a Mediator object. This would be a shame, because in production code we only need to create the mediator once, and don’t want to have the constructor function hanging around polluting the global namespace.

Surely other people have encountered this problem when testing immediate / self-involking / self-executing functions´. So what is ‘best-practice’?

  • 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-01T02:26:25+00:00Added an answer on June 1, 2026 at 2:26 am

    I think exposing the mediator constructor and having each test override the existing global member might be the best option. Exposing one object constructor would be a big issue. It sounds like the work-arounds are a lot more effort than just exposing on method.

    Something like:

    // mediator.js
    
    function createMediator(){ ... }
    
    window.mediator = createMediator();
    
    
    
    // In unit test
    
    beforeEach(function () {
      window.mediator = createMediator();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this in my controller: function foo() { // my code redirect(site_url('competitor/main'), 'refresh');
I have a function that takes a url to an Excel file, and then
I have a class called User with static function loginRequired(), which returns false if
Let's say I have a controller function with these lines: $this->load->view('stdHeader_view'); echo <div class='main'>;
I have a function designed to get a file's contents: bool getFileContents(std::string loc, std::string
I have a simple question. I was looking for function to download file. I
Does Eclipse have an analog to Visual Studio's Immediate Window, a window where I
An application specific example to illustrate my immediate problem: I have a metadata provider
I have been trying to get this one section of my UI to immediatly
Have a look at this picture alt text http://www.abbeylegal.com/downloads/2009-04-01/web%20part%20top%20line.jpg Does anyone know what css

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.