Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

139
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda