Skip to content

fix(expect): correct inverted failIfNoFirstInvocation logic in toHaveBeenCalledBefore/After#10687

Open
chatman-media wants to merge 1 commit into
vitest-dev:mainfrom
chatman-media:fix/spy-called-before-after-invocation-flag
Open

fix(expect): correct inverted failIfNoFirstInvocation logic in toHaveBeenCalledBefore/After#10687
chatman-media wants to merge 1 commit into
vitest-dev:mainfrom
chatman-media:fix/spy-called-before-after-invocation-flag

Conversation

@chatman-media

Copy link
Copy Markdown

isSpyCalledBeforeAnotherSpy has its two empty-invocation checks backwards. The spy under test never being called is gated by failIfNoFirstInvocation, while the other spy never being called always returns false regardless of the flag. It should be the opposite, per jest-extended's reference implementation.

Concretely: expect(neverCalledSpy).toHaveBeenCalledBefore(otherSpy, false) currently passes silently when it should throw, and expect(calledSpy).toHaveBeenCalledBefore(neverCalledSpy, false) throws when it shouldn't. Same inversion for toHaveBeenCalledAfter. For a matcher, letting a wrong assertion pass quietly is the worse failure mode.

Swapped the two branches and fixed the two existing tests that were locking in the wrong behavior, plus added one test per matcher for the previously-unreachable correct case.

…alledBefore/After

isSpyCalledBeforeAnotherSpy has the two empty-invocation checks backwards: the spy under test having zero calls was gated by the flag, while the comparison spy having zero calls always returned false. That's inverted from jest-extended's reference behavior and means e.g. expect(neverCalledSpy).toHaveBeenCalledBefore(otherSpy, false) silently passes when it should throw.

Fixed both branches and corrected the two existing tests that were asserting the wrong outcome, plus added one test per matcher for the case that used to be unreachable.
@github-actions github-actions Bot added the maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control label Jun 30, 2026
@github-actions

Copy link
Copy Markdown

Hello @chatman-media. Your PR has been labeled maybe automated because it appears to have been fully generated by AI with no human involvement.

To keep your PR open, please follow these steps:

  • Confirm that you are a real human. If you are an automated agent, disclose that
  • Confirm you've read, reviewed and stand behind its content
  • Confirm you've read the full issue along with all of its comments, as well as any linked issues and their comments
  • Make sure it follows our contribution guidelines and uses the correct GitHub template
  • Disclose any AI tools you used (e.g. Claude, Copilot, Codex)

Please, do not generate or format the response with AI. If you do not speak English, reply in your native language or use translation software like Google Translate or Deepl. If the response is generated, the PR will be closed automatically.

These measures help us reduce maintenance burden and keep the team's work efficient. See our AI contributions policy for more context.

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

Labels

maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control

1 participant