Angluar CLI generate component: test files are still modular

Discussão em 'Angular' iniciado por Wouter Vandenputte, Agosto 22, 2025.

  1. I created a component using the Angular CLI (quite recent version)

    ng --version
    19.2.14


    I did this using ng g c foo

    The problem I have with this is that the FooComponent is standalone (it should) but the test file however is not. When I run ng test I get the following error:


    Unexpected "FooComponent" found in the "declarations" array of the "TestBed.configureTestingModule" call, "FooComponent" is marked as standalone and can't be declared in any NgModule - did you intend to import it instead (by adding it to the "imports" array)?
    ​

    In order to fix this, I have to move FooComponent from here

    TestBed.configureTestingModule({
    declarations: [FooComponent],
    imports: [IonicModule.forRoot()]
    }).compileComponents();


    to here

    TestBed.configureTestingModule({
    imports: [IonicModule.forRoot(), FooComponent]
    }).compileComponents();


    Every time I generate component, service, guard, ... Why does it do that? Why the inconsistency? Is there a fix?

    Continue reading...

Compartilhe esta Página