Skip to content

Conversation

clydin
Copy link
Member

@clydin clydin commented Sep 5, 2025

This commit introduces a new E2E test to validate snapshot testing with the Vitest runner. The test covers both file-based and inline snapshots.

The test follows this sequence:

  1. Runs ng test to generate initial snapshots.
  2. Runs ng test again to ensure tests pass against the existing snapshots.
  3. Modifies the component to cause a mismatch.
  4. Runs ng test a final time and asserts that the command fails with a snapshot error.

To support the new snapshot matchers (toMatchSnapshot, toMatchInlineSnapshot) in the test environment, the vitest/globals types are now added to the tsconfig.spec.json by the applyVitestBuilder helper.

Closes #30439

@clydin clydin added the target: major This PR is targeted for the next major release label Sep 5, 2025
This commit introduces a new E2E test to validate snapshot testing with the Vitest runner. The test covers both file-based and inline snapshots.

The test follows this sequence:
1. Runs `ng test` to generate initial snapshots.
2. Runs `ng test` again to ensure tests pass against the existing snapshots.
3. Modifies the component to cause a mismatch.
4. Runs `ng test` a final time and asserts that the command fails with a snapshot error.

To support the new snapshot matchers (`toMatchSnapshot`, `toMatchInlineSnapshot`) in the test environment, the `vitest/globals` types are now added to the `tsconfig.spec.json` by the `applyVitestBuilder` helper.
@clydin clydin force-pushed the unit-test/vitest-snapshot-e2e branch from fa4f80a to 30e1d33 Compare September 5, 2025 20:26
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Sep 5, 2025
@clydin clydin 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 Sep 6, 2025
@clydin clydin merged commit 722c44f into angular:main Sep 6, 2025
32 of 33 checks passed
@clydin clydin deleted the unit-test/vitest-snapshot-e2e branch September 6, 2025 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge The PR is ready for merge by the caretaker area: @angular/build target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[@angular/build:unit-test][vitest] Vitest snapshot testing
2 participants