Skip to content

Conversation

@clydin
Copy link
Member

@clydin clydin commented Nov 19, 2025

Changes include:

  • 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.
  • 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.
  • 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.

@clydin clydin added the target: patch This PR is targeted for the next patch release label Nov 19, 2025
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.
@clydin clydin force-pushed the refactor/jasmine-fixes-1 branch from f1587ec to 9223c27 Compare November 19, 2025 22:25
@clydin clydin marked this pull request as ready for review November 19, 2025 22:25
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Nov 19, 2025
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Nov 20, 2025
@clydin clydin merged commit 7c6a643 into angular:main Nov 20, 2025
37 checks passed
@clydin
Copy link
Member Author

clydin commented Nov 20, 2025

This PR was merged into the repository. The changes were merged into the following branches:

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']));

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:

Suggested change
expect(myArray).toEqual(expect.arrayContaining(['a', 'b']));
expect(myArray).toEqual(['a', 'b']);

Copy link
Member Author

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]))

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

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: @schematics/angular target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants