fix(@schematics/angular): preserve Jasmine stub-by-default semantics for bare spies#33266
Open
clydin wants to merge 2 commits into
Open
fix(@schematics/angular): preserve Jasmine stub-by-default semantics for bare spies#33266clydin wants to merge 2 commits into
clydin wants to merge 2 commits into
Conversation
620ba09 to
aa35769
Compare
There was a problem hiding this comment.
Code Review
This pull request refactors the Jasmine-to-Vitest schematic spy transformer to append .mockReturnValue(undefined) by default to spyOn and spyOnProperty calls, preserving stub-by-default semantics unless chained with .and strategies. It also restructures the transformation logic into smaller helper functions to support chained spies with bracket notation, non-null assertions, type assertions, and satisfies expressions. The code review feedback recommends adding defensive checks to prevent potential runtime crashes when returnValue() or throwError() are called without arguments, and suggests using ts.isStringLiteralLike to more robustly handle bracket notation.
…for bare spies The refactor-jasmine-vitest schematic previously migrated bare spyOn and spyOnProperty calls as a direct mechanical rename to vi.spyOn. Since the APIs feature opposing default behaviors (with jasmine.spyOn stubbing by default and vi.spyOn calling through), this caused migrated test suites to silently change behavior. This update structurally analyzes the AST during translation to detect chained strategies, appending .mockReturnValue(undefined) precisely for bare spies to retain original Jasmine semantics. Fixes angular#33253
aa35769 to
1954ddb
Compare
1 task
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.
The refactor-jasmine-vitest schematic previously migrated bare spyOn and spyOnProperty calls as a direct mechanical rename to vi.spyOn. Since the APIs feature opposing default behaviors (with jasmine.spyOn stubbing by default and vi.spyOn calling through), this caused migrated test suites to silently change behavior.
This update structurally analyzes the AST during translation to detect chained strategies, appending .mockReturnValue(undefined) precisely for bare spies to retain original Jasmine semantics.