no-conditional-in-test
Configuration
rslint.config.ts
Rule Details
Disallow conditional logic in test bodies. A conditional usually indicates that a test is covering multiple execution paths, which can make it unclear which behavior the test is intended to verify. Prefer a separate test for each branch.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Conditionals outside test bodies, including conditionals in describe blocks,
hooks, and helper functions declared outside a test, are not reported.
Options
- First argument (optional): object with
allowOptionalChainingallowOptionalChaining: whether optional chaining (?.) is allowed inside test bodies. Default istrue.
When allowOptionalChaining is false, optional property access, element
access, and calls are also reported:
Examples of incorrect code with { "allowOptionalChaining": false }:
Examples of correct code with { "allowOptionalChaining": false }: