no-test-return-statement
Added in v0.9.4Configuration
rslint.config.ts
Rule Details
Disallow explicitly returning from tests. Tests in Jest should be void and not return values. If you are returning Promises then you should update the test to use async/await.
This rule reports the first return statement written directly in a test callback's block body. Returns nested in other statements or inside nested functions, and arrow functions without braces, are not reported. Hooks and describe callbacks are not checked.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Differences from upstream
- A callback passed by name is reported only while that name is used for nothing but test callbacks.
it('one', check); function check() { return expect(1).toBe(1); }is reported, but addingconst value = check();, exportingcheck, or reassigning it leaves it unreported, because the function's return value may be needed by those other uses. Upstream reports the function in all of these cases. - A callback bound with
const check = () => { ... }is checked like a function declaration. Upstream checks only function declarations passed by name.