Repository navigation
fix(@schematics/angular): migrate CallInfo returnValue and object in refactor-jasmine-vitest - #34538
Conversation
…refactor-jasmine-vitest Previously, only the `.args` property of a Jasmine `CallInfo` object obtained via `spy.calls.first()`, `spy.calls.mostRecent()`, or `spy.calls.all()[i]` was migrated. Accessing `.returnValue` or `.object` on these results left the property intact on the transformed `mock.calls[i]` tuple, producing code that fails type checking and throws at runtime. These properties are now mapped to the corresponding Vitest `MockContext` members: - `spy.calls.first().returnValue` -> `vi.mocked(spy).mock.results[0].value` - `spy.calls.all()[i].returnValue` -> `vi.mocked(spy).mock.results[i].value` - `spy.calls.mostRecent().returnValue` -> `vi.mocked(spy).mock.results.at(-1)?.value` - `spy.calls.first().object` -> `vi.mocked(spy).mock.contexts[0]` - `spy.calls.all()[i].object` -> `vi.mocked(spy).mock.contexts[i]` - `spy.calls.mostRecent().object` -> `vi.mocked(spy).mock.contexts.at(-1)` The separate `transformMostRecentArgs` and `transformAllCallsArgs` handlers have been consolidated into a single `transformCallInfoProperty` transformer, and the TODO for a bare `mostRecent()` call no longer fires when one of the supported properties is accessed.
There was a problem hiding this comment.
Code Review
This pull request enhances the Jasmine-to-Vitest migration schematics by expanding the Jasmine spy transformer to support additional CallInfo properties (.returnValue and .object) and handling transparent wrappers like type assertions and parenthesized expressions. The reviewer suggests improving the accuracy of the reported transformation messages by dynamically extracting the index expression's text instead of hardcoding 'i', which can be achieved by passing the sourceFile to getCallInfoAccess.
|
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. |
Previously, only the
.argsproperty of a JasmineCallInfoobject obtained viaspy.calls.first(),spy.calls.mostRecent(), orspy.calls.all()[i]was migrated. Accessing.returnValueor.objecton these results left the property intact on the transformedmock.calls[i]tuple, producing code that fails type checking and throws at runtime.These properties are now mapped to the corresponding Vitest
MockContextmembers:spy.calls.first().returnValue->vi.mocked(spy).mock.results[0].valuespy.calls.all()[i].returnValue->vi.mocked(spy).mock.results[i].valuespy.calls.mostRecent().returnValue->vi.mocked(spy).mock.results.at(-1)?.valuespy.calls.first().object->vi.mocked(spy).mock.contexts[0]spy.calls.all()[i].object->vi.mocked(spy).mock.contexts[i]spy.calls.mostRecent().object->vi.mocked(spy).mock.contexts.at(-1)The separate
transformMostRecentArgsandtransformAllCallsArgshandlers have been consolidated into a singletransformCallInfoPropertytransformer, and the TODO for a baremostRecent()call no longer fires when one of the supported properties is accessed.