Menu

1 / 2

vitest-fail-on-console: Stop Ignoring console.error in Your Tests

DEV Community·Recca Tsai·6 months ago
#qyKg0eHZ
#testing#vitest#node#software#console
Reading 0:00
15s threshold

Originally published at recca0120.github.io

All tests pass, but the terminal is full of red console.error output. This is common and easy to ignore — the tests passed, after all. But those errors don't appear out of nowhere. Something went wrong; nobody just noticed.

vitest-fail-on-console does one thing: if console.error or console.warn appears during a test, that test fails. It forces you to acknowledge these messages instead of letting them drown in noise.

Why console.error in Tests Is a Code Smell

Vitest doesn't care about console output by default. You can console.error all day and tests still pass.

The problem is that console.error usually means something. It might be:

A React prop type warning

An async error that was caught but not properly handled

A third-party package telling you you're using it wrong

An error handler in your own code getting triggered

When these appear in tests, the test is running in a slightly broken state — it just didn't throw.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.