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

363
Visualizações
How to run function in tests?

I'm a Java Developer but I want to have some experience also with NodeJS. In Java, when i make a function, then i can run this function in a simple way with using tests like below:

    @Autowired
    SomeService service;

    @Test
    public void testGet() {
        SomeDto dto = service.getDto(1L);
        log.info("Retrieved: {}", dto.getName());
    }

Right now I can run only this one test and check that my method work properly. But how to do this with using NodeJS? For example i have this method:

async getData(id: any): Promise<SomeDto> {
   return this.conn.getRepository(Client).findById(id);
}

how to run this method in tests like I'm doing it with Java?

PS. I don't want to create unit test and so on, I want only to run my functions with using tests

thanks for any help!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In nodejs (Or TS) we have lot of test framework, mocha is famous test framework

You can use mocha for BDD, TDD, ...

See mocha document in https://mochajs.org/

Below link help you to write test in nodejs and i hope helpful for you:

https://blog.logrocket.com/a-quick-and-complete-guide-to-mocha-testing-d0e0ea09f09d/


Tip: If you want use TDD you can use sinon package, this package is so good for TDD and fake function

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