Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!