-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Several improvements for Jasmine to Vitest refactor schematic #31878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how you do the same in Jest/Vitest:
| expect(myArray).toEqual(expect.arrayContaining(['a', 'b'])); | |
| expect(myArray).toEqual(['a', 'b']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not equivalent. The following passes but would fail with that transformation:
expect([1, 2]).toEqual(jasmine.arrayWithExactContents([2, 1]))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, yeah that makes sense
|
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. |
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.