Skip to content

Flaky test failure in vitest browser mode when passing strings to render #569

@ThiloAschebrock

Description

@ThiloAschebrock

Summary

Test files pass in isolation but fail in full-suite runs with:

  • Error: Cannot configure the test module when the test module has already been instantiated. Make sure you are not using inject before TestBed.configureTestingModule.

This error always appears together with:

  • TypeError: Cannot redefine property: ɵcmp

Environment

  • Angular 21.2.1
  • @testing-library/angular 19.1.0
  • vitest 4.0.18
  • @vitest/browser-playwright 4.0.18
  • Chromium browser mode via Angular unit-test builder or AnalogJS

Pattern that triggers the issue

  • Use render(...) from @testing-library/angular
  • Use template-string rendering (not component class rendering)
  • Run many tests/files in browser mode in the same run

Expected

Full-suite and isolated runs should behave consistently without TestBed/component metadata lifecycle errors.

Actual

In the larger suite, full runs intermittently fail with both errors (Cannot configure the test module... and Cannot redefine property: ɵcmp).

However, finding a minimal example to reproduce the issue consistently is challenging.

Workaround

Switching away from template-string wrapper patterns to explicit host components makes the failures disappear. I could, further, only see these failures in browser mode. Running a similar set of tests with JSDOM, did not cause these failures.

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