Several improvements for Jasmine to Vitest refactor schematic#31878
Merged
clydin merged 3 commits intoangular:mainfrom Nov 20, 2025
Merged
Several improvements for Jasmine to Vitest refactor schematic#31878clydin merged 3 commits intoangular:mainfrom
clydin merged 3 commits intoangular:mainfrom
Conversation
This commit enhances the jasmine-vitest schematic by adding mock names to `vi.fn()` instances created from `jasmine.createSpyObj`. This improves debugging in Vitest by providing meaningful names for mock functions, making test failures easier to understand and trace.
This commit adds a safety check to the `done` callback transformation in the `jasmine-vitest` schematic. Previously, if a `done` callback was used in an unhandled way (e.g., passed as an argument to a helper function), the schematic would remove the `done` parameter but leave the usage, causing runtime errors. Now, the transformer counts the total usages of the `done` callback and compares it to the number of usages it successfully transformed. If there are unhandled usages, it aborts the transformation for that specific test and adds a TODO comment, ensuring that no broken code is generated.
…Contents This commit improves the transformation of `jasmine.arrayWithExactContents` in the `jasmine-vitest` schematic. While Vitest does not have a direct equivalent for multiset equality, the schematic previously transformed this into a check for length and subset containment, which could lead to false positives (e.g., `[1, 1]` matches `[1, 2]`). Now, the schematic attaches a TODO comment to the generated code, explicitly warning the user that the transformation relies on `expect.arrayContaining` (a subset check) and advising them to verify strict content matching manually.
f1587ec to
9223c27
Compare
hybrist
approved these changes
Nov 20, 2025
Member
Author
alfaproject
reviewed
Nov 20, 2025
| expected: ` | ||
| // TODO: vitest-migration: Verify this matches strict array content (multiset equality). Vitest's arrayContaining is a subset check. | ||
| expect(myArray).toHaveLength(2); | ||
| expect(myArray).toEqual(expect.arrayContaining(['a', 'b'])); |
There was a problem hiding this comment.
This is how you do the same in Jest/Vitest:
Suggested change
| expect(myArray).toEqual(expect.arrayContaining(['a', 'b'])); | |
| expect(myArray).toEqual(['a', 'b']); |
Member
Author
There was a problem hiding this comment.
That's not equivalent. The following passes but would fail with that transformation:
expect([1, 2]).toEqual(jasmine.arrayWithExactContents([2, 1]))
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Changes include:
vi.fn()instances created fromjasmine.createSpyObj. This improves debugging in Vitest by providing meaningful names for mock functions, making test failures easier to understand and trace.donecallback transformation in thejasmine-vitestschematic. Previously, if adonecallback was used in an unhandled way (e.g., passed as an argument to a helper function), the schematic would remove thedoneparameter but leave the usage, causing runtime errors.jasmine.arrayWithExactContentsin thejasmine-vitestschematic. While Vitest does not have a direct equivalent for multiset equality, the schematic previously transformed this into a check for length and subset containment, which could lead to false positives (e.g.,[1, 1]matches[1, 2]). Now, the schematic attaches a TODO comment to the generated code, explicitly warning the user that the transformation relies onexpect.arrayContaining(a subset check) and advising them to verify strict content matching manually.