0%
Unit Testing with Vitest

Unit Testing with Vitest

A test you can't understand in ten seconds will be deleted rather than fixed

10-15 min

Unit Testing with Vitest

You take over a project that has been abandoned for eight months. The test suite has 340 files, and 12 of them are red. You open the first one: it's called test 4, it builds a 60-line object in a beforeEach shared by 18 tests, and its final assertion compares a whole object to a frozen literal. The failure message reports a difference on an updatedAt field. You don't know what this test was supposed to guarantee, or whether the product is broken. You disable it, and you never turn it back on.

There is nothing unusual about this scenario: it's the normal way a test suite dies. The real cost of a test isn't incurred when you write it, but when it fails six months later in front of someone who wasn't there. A good test reads like a sentence, fails with a message that points to the cause, and doesn't depend on any shared context you'd have to reconstruct in your head. Vitest won't do this work for you, but it removes enough friction (instant startup, targeted watch mode, readable diff messages) that you no longer have an excuse.

Comments

Comments are powered by GitHub Discussions

Sign in with GitHub to join the discussion

Link copied!