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

98
Visualizações
Test if the object was modified correctly within the function scope

Let's supose that I have a javascript function that behaves like that:

    function foo() {
        /* unnecessary code...*/
        const sendObjSomewhere = (param) => {/* anom function implementation */}
        return {
            async bar(obj) {
                try {
                    obj.name = obj.name.replace(/\w/g, '');
                    await sendObjSomewhere(obj);
                } catch () {
                     console.error('you messed up');
                }
            }
        }
    }

I tried to show only the important part -- the objName variable and the function. My goal is to test if the obj.name is formated properly.

I've tried to use some libs but, unfortunately, I'm only allowed to use mocha and node native assertions (even more unfortunately, not allowed to extend mocha with other libs). How can I intercept await sendObjSomewhere(obj); and see how the params are being sent? Any other ways to test it are very welcome.

I'm using mocha 9.1.3 and node 16

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