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

107
Visualizações
Unit test, how to use Sinon mock a function and assert it has been call

I am new to UnitTest. I have a setData function and trying to write test to it with mocha chai. I trying to mock the function2.setCode function that require from other module and assert it has been call when test the setData function. But have error about wrap undefined property when test. Anyone can help how to achieve that?

const function2 = require(../function2)
function setData(req) {
  if (!req) {
    return;
  }

  const data = function1(req);
  if (data) {
    const function2 = new function2(req);
    if (function2) {
      function2.setCode(data);
      );
    }
  }
}

My draft

describe('test', ()=>{
    context('setData', ()=>{
        it('function2.setCode should be call', ()=>{
            let mock = mock(setData);
            mock.expects("setCode").once();
            setData();
            mock.verify();
        })
    })
}
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