Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
Jest - Unit Testing a Namespaced File

Is it possible to write a unit test with Jest for a JavaScript file that is namespaced using the below format?

// utilities.js

var MyApp = MyApp || {};
MyApp.Common = MyApp.Common || {};
MyApp.Common.Utilities = new function(){
    this.getSomething = function(){  // Need to unit test this function
        return 'Something';
    }
}

If not, is there a better way to structure the namespaces to allow for unit testing?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you export MyApp like following example then in utilities.test.js you can

const {MyApp} = require('./utilities');

it('should work', ()=>{
  expect(MyApp.Common.Utilities.getSomething()).toEqual('something');
});

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!