Incomplete Assertion
ID |
javascript.assertions_complete |
Severity |
critical |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
JavaScript |
Tags |
assertion, reliability, testing |
Description
Reports an expect(actual) — or Vitest’s expectTypeOf(actual) — with no matcher chained onto it. The call builds the expectation object and the statement throws it away: nothing is compared.
Reported only when the builder’s result is discarded, i.e. the call is the whole of an expression statement. A result that is assigned, returned or passed on is handed to code this rule cannot see, which is the shape of a helper that hands a half-built expectation onward for its caller to finish.
A chain that ends on a property is judged by which property. expect(value).to.be.true is Chai’s complete assertion, where the property getter is what raises, while expect(value).not and expect(promise).resolves end on a word that only modifies the assertion still to come.
Rationale
// Bad
it('charges the card once', () => {
expect(charge.mock.calls.length); // builds an expectation, checks nothing
expect(receipt.total).not; // negates an assertion that never arrives
});
-
Both statements pass unconditionally, whatever the code under test did.
-
The line reads as an assertion in review and in the diff, so nobody looks for the missing matcher.
-
The mistake is a single omitted call, easy to make when an editor completes
expect(and the cursor moves on, and no run will ever point at it. -
The test’s title still claims the behaviour is checked, so the gap survives every later reading of the file.