Skip to content

feat(no-test-return-statement): disallow returning from a test body - #495

Open
unlikelyzero wants to merge 1 commit into
mskelton:mainfrom
unlikelyzero:feat/no-test-return-statement
Open

feat(no-test-return-statement): disallow returning from a test body#495
unlikelyzero wants to merge 1 commit into
mskelton:mainfrom
unlikelyzero:feat/no-test-return-statement

Conversation

@unlikelyzero

Copy link
Copy Markdown
Collaborator

Adds a no-test-return-statement rule, ported from jest/no-test-return-statement.

Playwright ignores whatever a test body returns. test('foo', () => somePromise) looks like it makes the test wait, but the test finishes immediately and any failure inside the promise is reported against a later test or lost entirely — await is what's wanted. A top-level return with no argument is dead code.

The rule reports a return at the top level of a test body only. Returns nested in conditionals, loops, or callbacks declared inside the test are ordinary control flow and aren't reported.

One deviation from the jest rule: test bodies passed by reference (test('foo', myTestFn)) aren't covered, because parseFnCall classifies those calls as config rather than test. That's consistent with how every other rule in this plugin behaves today, so it seemed better than special-casing it here.

Not enabled in the recommended config, matching eslint-plugin-jest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant