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

132
Views
How can I build mocks for Jasmine in old, vanilla JS project?

I am trying to add unit tests to an old vanilla JS project via Jasmine. I've read a little about using a specRunner.html page, but I've been hoping to include this as a git hook of some sort, instead of manually opening and confirming on a webpage.

This app runs by linking to all of the scripts in the index.html. There are no modules. It makes use of a global variable all the services are tacked onto to run the app.

Here's my current test set up, but I'm looking to improve it.

uat.js // this was existing already

globalVar.myUAT = (function () {
    // this code requires anotherObject for it's getInstance()
})();

module.exports = globalVar.myUAT; // I had to add this

uat.spec.js // this is all new

describe('my tests', () => {
    let anotherObject;
    beforeEach(() => {
        anotherObject = {...}; // I'm stubbing the object here
    }

    it('should instantiate', () => {
        spyOn(anotherObject, 'method').and.callFake(...);
        let uatClass = require('./uat.js');
        let uat = uatFile.getInstance(anotherObject);
        expect(uat).toBeTruthy();
    }
});

What improvements can I make? I hate the stubbing of anotherObject in my beforeEach. Should I abandon this and just stick with the specRunner solution?

about 4 years ago · Juan Pablo Isaza
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!