All tests pass. The bug is still there.
An assertion that is too weak misses a rendering defect; a regression test detects it before correction and after reintroduction.
A green test can answer the wrong question
The lab receives text and places it in an HTML paragraph. The expected rule is to preserve the entered text even when it contains angle brackets. The first function directly interpolates that input. An input of ‘<b>Texte</b>’ therefore becomes markup instead of remaining literal text.
const render = text => `<p>${text}</p>`;
assert.match(render('Texte'), /Texte/);The initial assertion passes. It proves that the word ‘Texte’ is present in this case, not that the content is treated as text. A separate reproduction displays the generated string with angle brackets: <p><b>Texte</b></p>. This teaching example is attributed to no tool or client.
Make a test fail on the expected behaviour
assert.equal(render('<b>Texte</b>'),
'<p><b>Texte</b></p>');This assertion fails on the initial function. It expresses the rule before changing code. The lab runs it inside an assertion expecting that failure, preserving a reproducible overall command while showing the red state.
If the business rule were to accept a subset of markup, this test would be incorrect. Validating the need precedes choosing the assertion. A test result must always be read alongside the rule it checks.
Two diffs to keep
- const render = text => `<p>${text}</p>`;
+ const render = text => `<p>${text.replaceAll('&','&')
+ .replaceAll('<','<').replaceAll('>','>')}</p>`;- assert.match(render('Texte'), /Texte/);
+ assert.equal(render('<b>Texte</b>'),
+ '<p><b>Texte</b></p>');Reintroduce the defect to check the test
Under Node.js 24.13.0, the test fails on the defective state, passes after correction and fails again when the initial function is reintroduced. The script preserves these four observations. The fix concerns an HTML text context; it is not universal escaping for attributes, URLs or scripts.
The test boundary also matters
A correct function can be bypassed by a caller, or its output changed by final rendering. The lab’s string check does not prove integration across an entire application. Add a browser flow when that risk belongs to the real change.
When reviewing a fix, ask which defect would make the new test fail. Reintroducing that specific defect provides more useful evidence than a count of added tests. Other possible defects still need examining according to the need’s scope.