valid-expect
Added in v0.8.1Configuration
rslint.config.ts
Rule Details
Enforce valid expect() usage in Rstest. expect must be called with the
right number of arguments, must be followed by a matcher, and asynchronous
assertions must be awaited or returned so their failures are not lost.
Examples of incorrect code:
Examples of correct code:
Rstest specifics
rstest's expect comes from @vitest/expect + chai, so this rule follows the
vitest behavior where it differs from jest:
- A second argument to
expectis allowed when it is a message string or template literal (expect(value, "msg")), andexpect.poll(fn, options)/expect.element(el, options)accept an options object. These do not triggertooManyArgs. - Chai property matchers are valid without a call:
expect(value).to.be.ok,expect(spy).to.have.been.called. They are not reported asmatcherNotCalled. - Forms with no assertion factory carry no assertion:
expect.assertions(1),expect.hasAssertions(), asymmetric matchers such asexpect.any(Number)and bare chains such asexpect.resolves.toBe(1)orexpect.toResolve()are not subject to argument or await checks.
expect is recognized from globals, @rstest/core imports and aliases,
require, namespace access, import.meta.rstest, test-context expect
(test('x', ({ expect }) => ...)), and @rstest/playwright.
Options
alwaysAwait— require every async assertion to be awaited, disallowingreturn.asyncMatchers— matcher names treated as asynchronous (must be awaited).minArgs/maxArgs— the required argument count forexpect.
The rule provides an automatic fix that inserts await (and async on the
enclosing function) for async assertions that are not awaited.