close

no-conditional-expect

Added in v0.8.0

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-conditional-expect': 'error',
    },
  },
]);

Rule Details

Disallows assertions that only run on some execution paths. A test can pass without checking anything when its assertion is skipped by a condition.

The rule recognizes expect from globals, imports, the local test context, Browser Mode, and Playwright integrations.

Incorrect

test('returns the user name', () => {
  if (user) {
    expect(user.name).toBe('Ada');
  }
});

Correct

test('returns the user name', () => {
  expect(user).toBeDefined();
  expect(user.name).toBe('Ada');
});