{"record":{"id":"7f576e3ab607df83","repo":"oxc-project/oxc","slug":"jest-tests-should-not-return-a-value","errorCode":null,"errorMessage":"Jest tests should not return a value","messagePattern":"Jest tests should not return a value","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/no_test_return_statement.rs","lineNumber":15,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{CallExpression, Expression, ReturnStatement},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_semantic::{AstNode, NodeId};\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{\n    context::LintContext,\n    utils::{JestFnKind, JestGeneralFnKind, PossibleJestNode, is_type_of_jest_fn_call},\n};\n\nfn no_test_return_statement_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Jest tests should not return a value\")\n        .with_help(\"Use `await` for async assertions or remove the return statement.\")\n        .with_note(\"Jest ignores returned values from tests.\")\n        .with_label(span)\n}\n\npub const DOCUMENTATION: &str = r\"### What it does\n\nDisallow explicitly returning from tests.\n\n### Why is this bad?\n\nTests in Jest should be void and not return values.\nIf you are returning Promises then you should update the test to use\n`async/await`.\n\n### Examples\n\nExamples of **incorrect** code for this rule:","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/no_test_return_statement.rs#L1-L33","documentation":"This is the oxlint `no-test-return-statement` rule (jest/vitest plugin). Jest ignores any value a test callback returns, so an explicit `return` inside a `test`/`it` callback is at best noise and at worst a misunderstanding: developers often `return` a promise thinking it is awaited, but the recommended pattern is `async`/`await`. The rule reports `ReturnStatement` nodes found inside jest test function callbacks.","triggerScenarios":"Any `return` statement in the callback passed to `test()`, `it()`, or their `.each`/`.skip`/`.only` variants — e.g. `test('x', () => { return fetchResult(); })` or `it('y', function () { return expect(x).toBe(1); });`.","commonSituations":"Copy-pasting a helper function body into a test without removing the return; old-style promise tests written before `async/await` that `return promise` to make Jest wait; returning the result of `expect()` as a stylistic habit carried over from other frameworks.","solutions":["For returned promises, mark the test callback `async` and `await` the call instead of returning it.","Delete the `return` keyword and keep the expression as a plain statement (`expect(x).toBe(1);`).","If the value is genuinely needed by the caller, move that logic out of the test into a helper."],"exampleFix":"// before\ntest('loads data', () => {\n  return fetchData().then((d) => {\n    expect(d).toBe('ok');\n  });\n});\n\n// after\ntest('loads data', async () => {\n  const d = await fetchData();\n  expect(d).toBe('ok');\n});","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n{ \"rules\": { \"jest/no-test-return-statement\": \"error\" } }\n\nnpx oxlint tests/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default to `async` test callbacks and `await` calls instead of returning promises.","When pasting helper bodies into tests, strip return keywords as part of the paste.","Enable the rule at error level so CI rejects new occurrences immediately."],"tags":["jest","vitest","oxlint","testing","async-await","static-analysis"],"backgroundTag":"test-returns-value","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}