Skip to content

TestBed imports not shared with non-standalone declarations (AOT) #66007

Closed as duplicate

Description

@dzonatan

Command

test

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

v20

Description

Standalone components added to imports in TestBed.configureTestingModule are not available to non-standalone components in declarations. This was working in v20 with Karma. See the reproduction below.

Minimal Reproduction

  1. ng new my-app
  2. Add this test file:
import { TestBed } from '@angular/core/testing';
import { Component } from '@angular/core';

it('should create', async () => {
  @Component({
    selector: 'comp-a',
    template: `Component A`,
  })
  class ComponentA {}

  @Component({
    standalone: false,
    selector: 'comp-b',
    template: `<comp-a />`,
  })
  class ComponentB {}

  TestBed.configureTestingModule({
    imports: [ComponentA],
    declarations: [ComponentB],
  });
  TestBed.createComponent(ComponentB);
});
  1. ng test

Exception or Error

✘ [ERROR] NG8001: 'comp-a' is not a known element:
1. If 'comp-a' is an Angular component, then verify that it is part of this module.
2. If 'comp-a' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. [plugin angular-compiler]

Your Environment

Angular CLI       : 21.0.3
Angular           : 21.0.4
Node.js           : 22.20.0
Package Manager   : npm 10.9.3
Operating System  : darwin arm64

┌───────────────────────────────────┬───────────────────┬───────────────────┐
│ Package                           │ Installed Version │ Requested Version │
├───────────────────────────────────┼───────────────────┼───────────────────┤
│ @angular-devkit/architect         │ 0.2100.3          │ ^0.2100.0         │
│ @angular-devkit/build-angular     │ 21.0.3            │ ^21.0.0           │
│ @angular-devkit/core              │ 21.0.3            │ ^21.0.0           │
│ @angular/build                    │ 21.0.3            │ ^21.0.3           │
│ @angular/cli                      │ 21.0.3            │ ^21.0.3           │
│ @angular/common                   │ 21.0.4            │ ^21.0.0           │
│ @angular/compiler                 │ 21.0.4            │ ^21.0.0           │
│ @angular/compiler-cli             │ 21.0.4            │ ^21.0.0           │
│ @angular/core                     │ 21.0.4            │ ^21.0.0           │
│ @angular/forms                    │ 21.0.4            │ ^21.0.0           │
│ @angular/platform-browser         │ 21.0.4            │ ^21.0.0           │
│ @angular/platform-browser-dynamic │ 21.0.4            │ ^21.0.0           │
│ @angular/router                   │ 21.0.4            │ ^21.0.0           │
│ ng-packagr                        │ 21.0.0            │ ^21.0.0           │
│ rxjs                              │ 7.8.2             │ ~7.8.0            │
│ typescript                        │ 5.9.3             │ ~5.9.2            │
│ vitest                            │ 4.0.15            │ ^4.0.8            │
└───────────────────────────────────┴───────────────────┴───────────────────┘

Anything else relevant?

No response

Activity

  1. changed the title [-]TestBed imports not shared with non-standalone declarations[/-] [+]TestBed imports not shared with non-standalone declarations (AOT)[/+] on Dec 11, 2025
  2. angular-automatic-lock-bot commented on Jan 11, 2026

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  3. locked and limited conversation to collaborators on Jan 11, 2026
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