Skip to content

Cleanup runs before test completion - unable to inspect rendered DOM in headed browser mode #34

Description

@rkrisztian

(Note: I used AI to compose the issue, but I have reviewed it thoroughly so that the information presented is still accurate.)

Expected Behavior

When running component tests in headed browser mode, the rendered component should remain visible in the viewport after the test completes, allowing developers to visually inspect the final state. This is how vitest-browser-react works — cleanup happens before a test is executed, not before the test completes.

Actual Behavior

In vitest-browser-angular, the DOM is cleared immediately when the test completes, making it impossible to inspect rendered output in headed mode. The viewport shows a blank/cleared state instead of the rendered component.

Impact

This significantly hinders debugging in headed browser mode because you cannot visually verify:

  • Component rendering at test completion
  • Visual layout issues
  • State that should persist through the test lifecycle

Reproduction Steps

  1. Enable browser mode with a headed provider (e.g., browser.name: 'chromium')
  2. Write a simple component test using vitest-browser-angular
  3. Run the test in headed mode
  4. Observe that the viewport is cleared immediately after the test assertions pass

Comparison with vitest-browser-react

The vitest-browser-react adapter maintains the rendered component until after the test finishes, then performs cleanup. This allows developers to pause and inspect the UI state during debugging.

This approach differs from @testing-library/react, which performs cleanup after tests. The before-test cleanup strategy allows developers to inspect the rendered components in the browser UI after a test completes, which is valuable for debugging.

(Source: https://deepwiki.com/vitest-community/vitest-browser-react/3.4-cleanup)

However, vitest-browser-angular works differently:

Cleanup Registration: Registers a cleanup hook to ensure the component is destroyed after the test
[...]
Teardown: After each test, fixture.destroy() is called [...]

(Source: https://deepwiki.com/vitest-community/vitest-browser-angular/2.1-render()-function-and-renderresult)

Although beforeEach is used to register the cleanup, the actual cleanup happens after the test ends. Maybe that is intentional, because Angular works with fixtures?

Additionally, I wanted to experiment with a workaround for myself, but I found no way to turn off automatic cleanup. Unlike the vitest-browser-react/pure import path, you can't import vitest-browser-angular/pure, there's no such exported path.

Request

Align vitest-browser-angular cleanup timing with vitest-browser-react:

  • Keep the rendered component visible in the viewport until the test completes.
  • Perform cleanup after the test finishes, not during the transition to the next test.
  • Allow manual cleanup.

Environment

  • vitest-browser-angular: 0.4.0
  • Angular: 21.2.17
  • Vitest: 4.1.9
  • Browser provider: playwright

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions