no-vacuous-string-assertions
Disallow string assertions with expected values that match anything.
Rule detailsโ
Assertions such as expect(text).toContain("") and
expect(text).toMatch(/.*/) look like string coverage, but they keep passing
for every string value. They do not prove that the code rendered the expected
label, token, error message, or format.
Incorrectโ
it("renders content", () => {
expect(renderedText()).toContain("");
});
it("renders content", () => {
expect(renderedText()).toMatch(/.*/);
});
it("renders content", () => {
expect(renderedText()).toEqual(expect.stringContaining(""));
});
Correctโ
it("renders content", () => {
expect(renderedText()).toContain("Saved");
});
it("renders content", () => {
expect(renderedText()).toMatch(/^Saved \d+ items$/);
});
What this rule reportsโ
This rule reports executable it(...) and test(...) callbacks that use:
toContain("")toMatch(/.*/)toMatch(/^.*$/)expect.stringContaining("")as the direct expected assertion value
The rule intentionally does not evaluate computed strings or regular expressions. Project-specific constants may encode meaningful expectations.
Optionsโ
This rule has no options.
When not to use itโ
Disable this rule only for tests that intentionally document matcher semantics. Product tests should assert the specific text or format produced by the code under test.
Rule catalog ID: R022