{"record":{"id":"a91f642841f7352b","repo":"oxc-project/oxc","slug":"test-must-end-with-an-assertion","errorCode":null,"errorMessage":"Test must end with an assertion","messagePattern":"Test must end with an assertion","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/jest/prefer_ending_with_an_expect.rs","lineNumber":24,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse oxc_str::CompactStr;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n    rules::PossibleJestNode,\n    utils::{\n        JestGeneralFnKind, convert_pattern, get_node_name, matches_assert_function_name,\n        parse_expect_jest_fn_call, parse_general_jest_fn_call,\n    },\n};\n\nfn prefer_ending_with_an_expect_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Test must end with an assertion\")\n        .with_help(\"Add an `expect` or assertion call as the last statement in the test block.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct PreferEndingWithAnExpect(Box<PreferEndingWithAnExpectConfig>);\n\n#[derive(Debug, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct PreferEndingWithAnExpectConfig {\n    /// An array of function names that should also be treated as test blocks.\n    additional_test_block_functions: Vec<CompactStr>,\n    /// A list of function names that should be treated as assertion functions.\n    /// Default: `[\"expect\"]`\n    #[serde(deserialize_with = \"deserialize_assert_function_names\")]\n    #[schemars(with = \"Vec<String>\")]\n    assert_function_names: Vec<Regex>,\n}","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/jest/prefer_ending_with_an_expect.rs#L6-L42","documentation":"This is oxlint's 'jest/prefer-ending-with-an-expect' diagnostic. It checks the body of each test/hook block and reports when the final statement is not an assertion call (expect(...) or a configured assert function). Tests that end with setup code, logging, or a dangling promise can pass without verifying anything, so the rule requires the last statement to be an assertion; the help says to add an expect as the last statement.","triggerScenarios":"Enable the rule and lint a test whose body's last statement is anything other than a call expression matching the expect/assert name patterns (configurable via additionalTestBlockFunctions and assertion matching utils). E.g. it('x', () => { setup(); save(user); }) triggers it.","commonSituations":"Fire-and-forget tests (calling an API without asserting the result), tests where the assertion sits inside an if that may be skipped, and tests ending with console.log debugging leftovers. Rule sets from strict presets flag these during CI, often surprising developers whose assertions are second-to-last after a stray statement.","solutions":["Add the missing expect(...) as the final statement of the test body: expect(result).toBe(true).","Reorder statements so the assertion is last (move logging or cleanup before it, or into afterEach hooks).","Move shared setup/cleanup out of the test body into before/after hooks so the test can end with its assertion.","For tests that legitimately cannot assert (smoke tests), disable the rule inline with // oxlint-disable-next-line jest/prefer-ending-with-an-expect."],"exampleFix":"// before\nit('saves the user', async () => {\n  const repo = new Repo();\n  await repo.save({ id: 1 });\n});\n\n// after\nit('saves the user', async () => {\n  const repo = new Repo();\n  await repo.save({ id: 1 });\n  expect(await repo.find(1)).toBeDefined();\n});","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["End every test body with the assertion that proves the behavior under test.","Keep setup and cleanup in before/after hooks so test bodies can end with expect(...).","Treat a test without a trailing assertion as incomplete during code review."],"tags":["lint","jest","testing","assertions","oxlint"],"backgroundTag":"jest-test-assertion","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"}