Implicitly Skipped Test
ID |
javascript.implicitly_skipped_test |
Severity |
high |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Code Smell |
Language |
JavaScript |
Tags |
reliability, testing |
Description
Reports a test whose body runs nothing: an empty callback, or one holding only a comment. The runner executes it and counts it as a pass.
The explicit forms are the fix, not the defect: it.skip, test.todo, xit and Mocha’s body-less it('title') all make the runner report the test as skipped or pending, which is what puts it on someone’s list. A comment inside the body is not a statement, so a body holding only a TODO is empty in the sense that matters here.
Only test cases are reported, not suites.
Rationale
// Bad
it('rejects an expired token', () => {});
it('rejects a revoked token', () => {
// TODO: needs a clock fake
});
-
Both are reported as passing tests, so the suite claims the behaviour named in the title is covered when nothing was tried.
-
It is the most expensive way to skip a test, because it is the only one invisible in the run’s output: a skipped test is listed as skipped, an empty one is listed as green.
-
The title is the only evidence the behaviour was ever meant to be tested, and it now argues against writing the test — one with that name already exists and passes.
-
A placeholder written during a rush survives indefinitely, since no run, report or gate distinguishes it from a real test.
Remediation
Write the test, or skip it explicitly so the run says so.
// Good — the run reports it as skipped, with the reason in the title
it.skip('rejects a revoked token (needs a clock fake)', () => {});
// Good — the test states its expectation
it('rejects an expired token', () => {
expect(() => verify(expiredToken)).toThrow('expired');
});