Spirolo

absence-anchor

A render test that only checks that things are absent.

advisoryUNADJUDICATED

16 / 20 true, 95% Wilson interval 0.58 to 0.92, on 12 open-source projects.

Shown by default at info. Gates only if you raise its severity.

What it reports

Every assertion in the test checks that something is absent (queryBy* returns null, not.toBeInTheDocument()), and none checks that the render produced anything. The test would still pass if the component rendered nothing, or crashed after mounting.

Example

it('shows no error for a valid email', () => {
  render(<EmailField value="ada@example.com" />);
  expect(screen.queryByRole('alert')).not.toBeInTheDocument();
});

What to do

Add an assertion that something the render must show is there, next to the absence check: a getBy* or findBy* query, or a plain jest-dom matcher.

expect(screen.getByRole('textbox')).toHaveValue('ada@example.com');
expect(screen.queryByRole('alert')).not.toBeInTheDocument();

Make it gate

It reports at info until you raise it:

// .spirolorc.jsonc
{ "rules": { "absence-anchor": "warn" } }

spirolo explain absence-anchor prints the same claim and status from your installed binary.

On this page