Repository navigation
fix(@schematics/angular): keep the default getter access type of spyOnProperty in refactor-jasmine-vitest - #34543
Conversation
…nProperty in refactor-jasmine-vitest Jasmine spies on getter when `spyOnProperty` gets no access type, migration turned `spyOnProperty(obj, 'prop')` into `vi.spyOn(obj, 'prop')`, which Vitest treats as method spy, so converted spec failed with TS2769 now `'get'` is passed when access type is omited, explicit one is kept
There was a problem hiding this comment.
Code Review
This pull request updates the Jasmine-to-Vitest schematic transformer to correctly handle spyOnProperty calls. When spyOnProperty is invoked with only two arguments, the transformer now appends 'get' as the third argument to vi.spyOn to match Jasmine's default behavior. Additionally, unit tests have been updated and added to verify this default behavior, chained calls, and explicit access types. There are no review comments, and we have no feedback to provide.
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
PR Type
What is the current behavior?
Issue Number: N/A
refactor-jasmine-vitestdrops default access type ofspyOnPropertyJasmine uses
'get'when third argument is missing,vi.spyOnwithout it is typed and run as method spyThis spec passes on Jasmine:
ng g @schematics/angular:refactor-jasmine-viteston 22.3.0-next.3 turns it intovi.spyOn(session, 'user').mockReturnValue('mocked')andng testfails to build:Without type check Vitest throws
vi.spyOn() can only spy on a functionat runtimeWhat is the new behavior?
transformPrimarySpyadds'get'whenspyOnPropertyhas two arguments, explict access type is kept as isSame spec converts to
vi.spyOn(session, 'user', 'get').mockReturnValue('mocked')and passes underng testExisting case in
jasmine-spy_spec.tsexpectedvi.spyOn(service, 'myProp').mockReturnValue(undefined)for barespyOnProperty, so it pinned this outputUpdated it and added two cases, chained one and explicit
'set', updated and chained ones fail on mainDoes this PR introduce a breaking change?
Other information
Bare
spyOnProperty(obj, 'prop')still gets.mockReturnValue(undefined)from #33266, so after this change it compiles only when getter type allowsundefined, same as barespyOnon method that returnsstring