close

valid-expect-in-promise

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/valid-expect-in-promise': 'error',
    },
  },
]);

Rule Details

Requires promise chains containing Rstest assertions to be returned or awaited. Otherwise the test can finish before the assertion runs or before its failure is reported.

Both Rstest expect and Chai assert calls are recognized. A promise chain may also be returned from the test callback.

Incorrect

test('loads a user', () => {
  loadUser().then((user) => {
    expect(user.name).toBe('Ada');
  });
});

Correct

test('loads a user', async () => {
  await loadUser().then((user) => {
    expect(user.name).toBe('Ada');
  });
});