Skip to content

Bug - Error: Unexpected "AppComponent" found in the "declarations" array of the "TestBed.configureTestingModule" call #149

@wizardnet972

Description

@wizardnet972

Hi, I encountered an issue when creating a domain with the app.

In the app.component.spec.ts file, I received the following error:

AppComponent > should create the app

Error: Unexpected "AppComponent" found in the "declarations" array of the "TestBed.configureTestingModule" call, "AppComponent" 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)?Jest

The issue occurs because AppComponent is a standalone component. Standalone components should be listed in the imports array instead of declarations.

Here’s the file that caused the issue:
https://github.com/angular-architects/nx-ddd-plugin/blob/main/libs/ddd/src/generators/domain/files/standalone-app/app/app.component.spec.ts__tmpl__#L7

And here’s the content of the file:

import { TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';

describe('AppComponent', () => {
  beforeEach(async () => {
    await TestBed.configureTestingModule({
      declarations: [AppComponent], // This should be 'imports' instead
    }).compileComponents();
  });

  it('should create the app', () => {
    const fixture = TestBed.createComponent(AppComponent);
    const app = fixture.componentInstance;
    expect(app).toBeTruthy();
  });

  it(`should have as title 'luggage'`, () => {
    const fixture = TestBed.createComponent(AppComponent);
    const app = fixture.componentInstance;
    expect(app.title).toEqual('luggage');
  });

  it('should render title', () => {
    const fixture = TestBed.createComponent(AppComponent);
    fixture.detectChanges();
    const compiled = fixture.nativeElement as HTMLElement;
    expect(compiled.querySelector('h1')?.textContent).toContain(
      'Welcome luggage'
    );
  });
});

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