close

expect-expect

Added in v0.8.1

Configuration

PresetConfigured Value
✅ rstestPlugin.configs.recommended"warn"
rslint.config.ts
import { defineConfig, rstestPlugin } from '@rslint/core';

export default defineConfig([
  rstestPlugin.configs.recommended,
  {
    rules: {
      'rstest/expect-expect': 'error',
    },
  },
]);

Rule Details

Requires every Rstest test or it callback to contain an assertion. This prevents tests from passing after exercising code without verifying its result.

By default, both expect and Chai's assert count as assertions. test.todo and it.todo are exempt because they intentionally have no callback; globals, imports, aliases, parameterized tests, fixtures, and Playwright integrations are recognized.

Incorrect

test('creates a user', async () => {
  await createUser({ name: 'Ada' });
});

Correct

test('creates a user', async () => {
  const user = await createUser({ name: 'Ada' });

  expect(user.name).toBe('Ada');
});

Options

{
  "rstest/expect-expect": [
    "error",
    {
      "assertFunctionNames": ["expect", "assert", "assertUser"],
      "additionalTestBlockFunctions": ["scenario"]
    }
  ]
}
OptionTypeDefaultDescription
assertFunctionNamesstring[]["expect", "assert"]Function names or patterns treated as assertions. Setting it replaces the default list.
additionalTestBlockFunctionsstring[][]Additional functions whose callbacks are treated as test blocks.