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.
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: ɵcmpEnvironment
21.2.1@testing-library/angular19.1.0vitest4.0.18@vitest/browser-playwright4.0.18Pattern that triggers the issue
render(...)from@testing-library/angularExpected
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...andCannot 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.