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

249
Visualizações
Jest, test a logger function (console.log to terminal)

I have a function that logs to the terminal.

How could I test what is printed there?

I want to test the colors of the printed text.

Currently, I just have this:

it('should return colored log', async () =>  {
  const receivedValue = await logger.log('some cyan title', 1);
  expect(receivedValue).toEqual(expectedValue);
});

I don't know which assertion of technique should I use to test what is being printed on the terminal. This the result of calling the function:

enter image description here

The function is pretty simple:

const log = async (title, level = 0) => {
  console.log(colorMessage(CYAN, title));  // THIS is what I want to catch for the test
  printMemory()
  if (level = 1) { more code... }
}

Any idea?

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