GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — New AOT option for Karma doesn't play nicely with TestBed.overrideComponent · Issue #30017 · angular/angular-cli

New AOT option for Karma doesn't play nicely with TestBed.overrideComponent #30017

New issue
Copy link
New issue
Copy link
Closed
#30021
Closed
New AOT option for Karma doesn't play nicely with TestBed.overrideComponent#30017
#30021
Copy link
Labels
area: @angular/builddevkit/build-angular:karma

Description

@hamfastgamgee
hamfastgamgee
opened on Apr 3, 2025
Issue body actions

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

No response

Description

When running Karma in the new-to-19.2.x AOT mode, if you have any tests that use TestBed.overrideComponent() to specify different metadata to the component (an override to the providers property, for example), the test fails with an error about missing the @component decorator or having missing metadata. The error is thrown from invalidTypeError in test_bed_compiler.ts. As far as I could tell, the getAnnotation function in the resolver was returning null instead of Component, causing the error to be tripped. I assume the AOT build is stripping this metadata/the decorator before this check is made. I couldn't find any way to work around the issue other than rearchitecting my component so that I was no longer needing to make the overrideComponent call. As long as overrideComponent was in the stack at all, regardless of what parameters I passed to it, the tests failed due to missing metadata.

I have not tested any of the other types of overrides, but given that most of the code in the TestBed compiler is in common between the decorated types, I would assume they all are impacted in AOT mode.

Minimal Reproduction

Create a simple valid component, turn on AOT for Karma, and make a test where you use TestBed.overrideComponent to reset metadata. You don't even need to specify an actual override in the second parameter to trigger the issue: TestBed.overrideComponent(YourComponent, {}) triggers the failure.

Exception or Error

_<class name> class doesn't have @Component decorator or is missing metadata.

Your Environment

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 19.2.6
Node: 22.14.0
Package Manager: npm 11.2.0
OS: win32 x64

Angular: 19.2.5
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.1902.6
@angular-devkit/build-angular     19.2.6
@angular-devkit/core              19.2.6 (cli-only)
@angular-devkit/schematics        19.2.6
@angular/cdk                      19.2.8
@angular/cli                      19.2.6
@angular/material                 19.2.8
@angular/material-luxon-adapter   19.2.8
@schematics/angular               19.2.6
rxjs                              7.8.2
typescript                        5.8.2
zone.js                           0.15.0

Anything else relevant?

No response

Activity

  1. alan-agius4
    added
    area: @angular-devkit/build-angular
    devkit/build-angular:karma
    area: @angular/build
    and removed
    area: @angular-devkit/build-angular
    on Apr 3, 2025
  2. alan-agius4
    linked a pull request that will close this issuefix(@angular/build): include component test metadata in development builds #30021on Apr 3, 2025
  3. clydin
    closed this as completedin #30021on Apr 3, 2025
  4. angular-automatic-lock-bot commented on May 4, 2025

    @angular-automatic-lock-bot
    angular-automatic-lock-botBot
    on May 4, 2025
    More actions

    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.

  5. angular-automatic-lock-bot
    locked and limited conversation to collaborators on May 4, 2025
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

    area: @angular/builddevkit/build-angular:karma

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.