Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda