Repository navigation
Conversation
…ne.SpyObj variables in refactor-jasmine-vitest `let svc: jasmine.SpyObj<T>; svc = jasmine.createSpyObj(...)` from Angular testing guide became `MockedObject<T>` variable assigned an object literal with only spied methods, which fails with TS2322 after migration and nothing in report points to it when createSpyObj initializes or is assigned to variable annotated with `jasmine.SpyObj<T>`, literal is now cast `as MockedObject<T>`, declaration is looked up in nearest enclosing block so same name in another describe gets its own type
There was a problem hiding this comment.
Code Review
This pull request enhances the Jasmine-to-Vitest refactoring schematic by casting jasmine.createSpyObj calls to MockedObject<T> when they are assigned to or initialize a variable annotated with jasmine.SpyObj<T>. This ensures proper type safety and compatibility with Vitest. The review feedback suggests utilizing the existing getUnwrappedParent utility function instead of manually unwrapping parenthesized expressions to handle other transparent wrappers like non-null assertions or type assertions more robustly.
…r jasmine.SpyObj variables in refactor-jasmine-vitest
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.
PR Checklist
PR Type
What is the current behavior?
Issue Number: N/A
Pattern from Angular testing guide
is migrated to
MockedObject<HeroService>variable and object literal with onlygetHeroes. JasminecreateSpyObjreturnsanyso it compiled before, after migrationtscfails withFile is reported as transformed and there is no TODO
What is the new behavior?
When
createSpyObjinitializes or is assigned to variable annotated withjasmine.SpyObj<T>, literal is castas MockedObject<T>and type import is added. Declaration is looked up in nearest enclosing block, sosvcdeclared in twodescribeblocks gets its own type in each. Migrated spec from above passestsc --strict(TS 6.0, vitest 5.0)New spec cases cover assignment, initializer and two describe blocks with same name, they fail on main
Does this PR introduce a breaking change?
Other information
Cast types members that were not spied as present, same as
jasmine.SpyObj<T>with untypedcreateSpyObjdid before migration. Other option is TODO without cast, I went with cast since it keeps migrated tests compiling