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
alan-agius4
left a comment
There was a problem hiding this comment.
Thanks for working on this. I left a few inline comments regarding parent unwrapping when a type assertion is already present, handling explicit type arguments on createSpyObj<T>, and union types.
…r jasmine.SpyObj variables in refactor-jasmine-vitest Address review: use explicit type argument of createSpyObj, look into union types and keep an existing cast instead of adding a second one. Co-authored-by: Alan Agius <alanagius@google.com>
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