close

no-standalone-expect

Added in v0.8.1

Configuration

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

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

Rule Details

Disallows executable assertions outside a test callback. Assertions at module scope or directly in a suite run while the test file is registered, not as part of a test case.

Assertions inside helper functions are allowed because a test can call them. Static helpers such as expect.any() and expect.extend() are also allowed at module scope.

Incorrect

describe('user service', () => {
  expect(createUser({ name: 'Ada' }).name).toBe('Ada');
});

Correct

describe('user service', () => {
  test('creates a user', () => {
    expect(createUser({ name: 'Ada' }).name).toBe('Ada');
  });
});

Options

{
  "rstest/no-standalone-expect": [
    "error",
    { "additionalTestBlockFunctions": ["scenario"] }
  ]
}
OptionTypeDefaultDescription
additionalTestBlockFunctionsstring[][]Additional functions whose callbacks are treated as test blocks.