feat(rstest): add valid-expect-with-promise rule - #2151
Merged
Merged
Conversation
elecmonkey
marked this pull request as ready for review
September 13, 2026 19:01
fansenze
reviewed
Sep 16, 2026
fansenze
left a comment
Contributor
There was a problem hiding this comment.
Found three reproducible false negatives. The existing targeted Go tests pass, but regression probes for the examples below each produce zero diagnostics.
elecmonkey
marked this pull request as draft
September 16, 2026 04:33
elecmonkey
marked this pull request as ready for review
September 16, 2026 12:15
elecmonkey
force-pushed
the
feat/rstest-valid-expect-with-promise
branch
from
September 16, 2026 12:20
3189081 to
d0b9895
Compare
fansenze
approved these changes
Sep 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Assertions on Promise values need
resolvesorrejectsto inspect the settled value rather than the Promise object itself. Conversely, applying either modifier to a non-promise subject fails at runtime.Rstest adds framework-specific cases that require type-aware handling:
expect(...).rejectsinvokes function subjects without arguments,expect.softand Chai assertion chains share ordinary expect semantics, whileexpect.pollandexpect.elementprovide separate asynchronous assertion APIs.Related #935
Changes
Add the type-aware
rstest/valid-expect-with-promiserule and register it outside therecommendedpreset.The rule recognizes Rstest globals, named and renamed imports, namespace and CommonJS forms,
rstack/test,import.meta.rstest, Playwright, and Test Context expect calls. It checks ordinaryexpectandexpect.softassertions, including promise modifiers between Chai assertions, and excludesexpect.pollandexpect.element.TypeScript expressions that preserve their runtime value—
as, angle-bracket assertions,satisfies, non-null assertions, and parentheses—are handled consistently across member extraction, call-chain traversal, root resolution, andimport.meta.rstestrecognition. This behavior remains opt-in so existing parser consumers retain their established wrapper boundaries.Chai subject transformations such as
property,ownProperty, andhaveOwnPropertyare tracked in source order. The rule checks the subject used by each subsequent matcher or promise modifier while conservatively stopping when a transformed subject cannot be determined.Native Promise instances and subclasses are recognized through the shared default-library symbol helper, while Promise constructors remain non-promise subjects. With
checkThenables: true, custom thenables must expose athenmethod whose fulfillment and rejection parameters are both callable.For callable subjects passed to
.rejects, the rule uses TypeScript call resolution to inspect the return type selected by a zero-argument call, matching Rstest runtime behavior across overloaded and generic functions.Add the complete
eslint-plugin-jest@29.16.0test suite, Rstest-specific and tsgo edge cases, source-only and compiler-backed capability proofs, JavaScript integration coverage, runtime probes, differential checks, and user documentation.Credits
Adapted from
eslint-plugin-jest@29.16.0'svalid-expect-with-promiserule.