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:
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?