Reviewer · Testing
Validate test effectiveness
A test is only useful if it actually distinguishes correct behavior from the bug it guards against. Before merging a new or regression test, verify that it fails against the old/buggy implementation and passes with the fix — a test that passes either way (e.g. because it only checks a side effect like "does not throw" instead of the real invariant, or...
A test is only useful if it actually distinguishes correct behavior from the bug it guards against. Before merging a new or regression test, verify that it fails against the old/buggy implementation and passes with the fix — a test that passes either way (e.g. because it only checks a side effect like “does not throw” instead of the real invariant, or because it exercises a different code path than the one changed) provides false confidence. Target the exact seam that changed: prefer observing real, public behavior (DOM output, emitted events, rendered trees) over mocking or asserting on internal implementation details, since mocking internals can hide path divergence and becomes brittle to refactors. When changing existing tests, keep already-covered scenarios intact and add new cases additively rather than replacing them, so coverage never regresses.
For example, a regression test for a re-entrant scheduler guard should include a case with a task continuation, since a simpler case can pass even with the guard removed:
it('re-entrant message event preserves a task continuation', () => {
const performWorkUntilDeadline = new global.MessageChannel().port1.onmessage;
scheduleCallback(NormalPriority, () => {
runtime.log('Task');
performWorkUntilDeadline();
return () => runtime.log('Continuation');
});
runtime.fireMessageEvent();
runtime.assertLog(['Message Event', 'Task', 'Post Message']);
runtime.fireMessageEvent();
runtime.assertLog(['Message Event', 'Continuation']);
});
This fails on the unguarded implementation (it throws when storing the continuation) and passes with the fix, proving the test actually pins the behavior being protected.