fix(expect): correct inverted failIfNoFirstInvocation logic in toHaveBeenCalledBefore/After#10687
Open
chatman-media wants to merge 1 commit into
Open
Conversation
…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.
|
Hello @chatman-media. Your PR has been labeled To keep your PR open, please follow these steps:
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. |
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.
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 returnsfalseregardless 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, andexpect(calledSpy).toHaveBeenCalledBefore(neverCalledSpy, false)throws when it shouldn't. Same inversion fortoHaveBeenCalledAfter. 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.