Skip to content
Sarj Code Standards

no-negative-only-http-status-assertion

Assert the intended HTTP status instead of only excluding a server error.

Why

A response can avoid status 500 while still fail with an unrelated 400, 401 or 404, so the test can pass without exercising the intended behavior.

Fix

Assert the expected response status or a deliberately bounded success/error contract. Preserve negative assertions that supplement an exact assertion for the same response.

Examples

Before — flagged A missing route can still pass this test
src/api.test.ts
import { test, expect } from "vitest";
test("reads", async () => {
const response = await fetch("/versions");
expect(response.status).not.toBe(500);
});
After — preferred Assert the API's intended result
src/api.test.ts
import { test, expect } from "vitest";
test("reads", async () => {
const response = await fetch("/versions");
expect(response.status).toBe(200);
});